码迷,mamicode.com
首页 > 其他好文 > 详细

django验证码

时间:2017-06-20 09:47:44      阅读:169      评论:0      收藏:0      [点我收藏+]

标签:https   下载   中间   migration   如何   style   验证码   htm   tps   

搭建网站很经常要用到验证码,django中就有这样的中间件django-simple-captha

githup地址https://github.com/mbi/django-simple-captcha.git

下载完之后,切换到下载的目录下pip install django-simple-captcha安装

如何使用

一在setting中install_app中添加captcha

二运行python manage.py makemigrations captcha,python manage.py migrate captcha

三在urls中添加

url(r^captcha/, include(captcha.urls)),

在form中添加一个CaptchaField

from django import forms
from captcha.fields import CaptchaField

class CaptchaTestForm(forms.Form):
    myfield = AnyOtherField()
    captcha = CaptchaField()

到时候验证form的时候如果验证码不正确会提示不合法

四在html添加captcha

<form action=‘.‘ method=‘POST‘>
    {{ form.captcha }}
    <input type="submit" />
    <button class=‘js-captcha-refresh‘></button>
</form>

注意点击更改验证码要自己写js实现哦

 

django验证码

标签:https   下载   中间   migration   如何   style   验证码   htm   tps   

原文地址:http://www.cnblogs.com/lgh344902118/p/7052625.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!