您好,登錄后才能下訂單哦!
github詳情:
http://django-simple-captcha.readthedocs.io/en/latest/usage.html
pip install django-simple-captcha==0.4.6
將captcha添加到setting的app中:
以下添加到urls中:
url(r'^captcha/', include('captcha.urls')),
register.html中,調(diào)入下面:
{{ register_from.captcha }}
自動(dòng)生成驗(yàn)證碼圖片和input輸入框
# 驗(yàn)證碼from captcha.fields import CaptchaField
# form對(duì)注冊(cè)表單的驗(yàn)證class RegisterForm(forms.Form): email = forms.EmailField(required=True) password = forms.CharField(required=True, min_length=5) # 驗(yàn)證碼,參數(shù):錯(cuò)誤信息 captcha = CaptchaField(error_messages={'invalid': '驗(yàn)證碼錯(cuò)誤啊'})
# 密碼加密 from django.contrib.auth.hashers import make_password
class RegisterView(View): def get(self, request): register_from = RegisterForm() return render(request, "register.html", {'register_from': register_from}) def post(self, request): register_from = RegisterForm(request.POST) if register_from.is_valid(): user_name = request.POST.get('username', '') pass_word = request.POST.get('password', '') user_profile = UserProfile() user_profile.username = user_name user_profile.password = pass_word # 對(duì)密碼加密 user_profile.password = make_password(pass_word) user_profile.save() # 保存到數(shù)據(jù)庫(kù) pass return render(request, "register.html", {'register_from': register_from})
在</form>前添加:
{% csrf_token %}
免責(zé)聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如果涉及侵權(quán)請(qǐng)聯(lián)系站長(zhǎng)郵箱:is@yisu.com進(jìn)行舉報(bào),并提供相關(guān)證據(jù),一經(jīng)查實(shí),將立刻刪除涉嫌侵權(quán)內(nèi)容。