python 驗證碼庫 captcha的使用以及遇到的問題解決

版權聲明:本文爲博主原創文章,未經博主允許不得轉載。 https://blog.csdn.net/u012896330/article/details/75669828


先附上庫的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




發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章