django验证码django-simple-captha

搭建网站很经常要用到验证码,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实现哦

 

posted @ 2017-06-20 09:04  菲菲菲菲菲常新的新手  阅读(393)  评论(0编辑  收藏  举报