您的位置:首页 > 编程语言 > Python开发

python 验证码库 captcha的使用以及遇到的问题解决

2017-07-21 18:02 465 查看
先附上库的GitHub地址:https://github.com/mbi/django-simple-captcha

看下帮助文档,如果把这个库应用到我们的项目中

1.Download django-simple-captcha using pip by running: pip install django-simple-captcha 首先pip安装这个库

2.. Add captcha to the INSTALLEDAPPS
in your settings.py 然后在settings.py-->INSTALLEDAPPS
INSTALLED_APPS = [
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
'operation',
'courses',
'users',
'organization',
'xadmin',
'crispy_forms',
'captcha'

]


3..Run python manage.py syncdb (or python manage.py migrate if you are managing database migrations via South) to create the required database tables

执行makemigrations 命令 以及 migrate,生成对应的数据库文件,可以查看下数据库


4.Add an entry to your urls.py:配置url
urlpatterns = [
url(r'^xadmin/', xadmin.site.urls),
url('^$', TemplateView.as_view(template_name='index.html'), name="index"),
url('^login/$', LoginView.as_view(), name="login"),
url('^register/$', RegisterView.as_view(), name="register"),
url(r'^captcha/', include('captcha.urls')),
]


这样我们准备工作就做好了,注册用到了这个验证码问题,具体的怎么实现的显示可以移步到登录注册看,

当我们把所有代码逻辑写出执行,发现并没有出现预想的结果。而是。。。。。



然后一脸懵逼的 F12看了下竟然 。。。。



然后我就各种问啊,请教啊,结果还是好的,



windows系统,使用PIL库的ImageFont.truetype()方法时,报错:

The _imagingft C module is not installed

说明自己电脑里安装的PIL库缺少一个freetype的库文件,我也手动安装了这个库,出现了_imagingft.pyd,但是import _imagingft时报错说DLL无法加载。

现在已解决了这个问题,解决方法:

1、卸载原来版本的PIL

pip uninstall pil

2、重新安装一个已经包含freetype库的PIL安装包,可以从该地址下载,并安装。

http://download.csdn.net/detail/ivy94419/9465338


                                            
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  django 验证码
相关文章推荐