pip install django-******-captcha==0.4.6這是使用於django1.9的
在settings.py中加入
['django.contrib.admin'
,'django.contrib.auth'
,'django.contrib.contenttypes'
,'django.contrib.sessions'
,'django.contrib.messages'
,'django.contrib.staticfiles'
,'users'
,'courses'
,'organization'
,'operation'
,'xadmin'
,'crispy_forms'
,'captcha',]
在forms.py中加入
from captcha.fields import captchafield
class
registerform
(forms.form)
: email = forms.emailfield(required=
true
) password = forms.charfield(required=
true
, min_length=5)
captcha = captchafield(error_messages=
)#這裡可以自定以錯誤資訊
配置url
from django.conf.urls import url, include
+url(r'captcha/'
, include(
'captcha.urls'))
,
在views.py中新增
#下面的函式可以對密碼進行加密
from django.contrib.auth.hashers import make_password
from
.forms import loginform, registerform
#在檢視中建立
class
registerview
(view)
:def
get(self, request)
: register_form = registerform(
)return render(request,
'register.html'
,)
html**
class
="form-group marb8 captcha1 "
>
>
驗 證 碼label
>
}//這裡不用定義input,它會自動的生成input和驗證碼
div>
Django1 9學習筆記
等 django1.9的templates系統和1.7有些許不一樣,原來的templates系統要由使用者自己定義。如 template path os.path.join base dir,templates template dirs put strings here,like home htm...
Django 1 9 靜態檔案配置
django 靜態檔案的配置涉及到settings 中的三個配置項static url staticfiles dirs及static root 1.開發伺服器中靜態檔案的配置及應用 1 static url 配置 預設情況下 settings 配置 static url static 2 stat...
Django 1 9 開發web專案
django.contrib.admin django.contrib.auth django.contrib.contenttypes django.contrib.sessions django.contrib.messages django.contrib.staticfiles rest f...