Django+Ubuntu web开发验证码插件配置

原理:hash_key和用户输入的验证码发送到数据库作联合查询

1.在项目虚拟环境中安装captcha
pip install django-simple-captcha ==0.4.6

2.在setting中设置
INSTALLED_APPS = ['captcha',]

3.在url中进行设置
url(r'^captcha/', include('captcha.urls')),

4.生成注册表
python manage.py makemigrations
python manage.py migrate

5.创建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()
设置中文显示:captcha = CaptchaField(error_messages={"invalid": u"验证码错误"})

6.在views函数中实例化并传入到html页面
{{ register_form.captche }}

你可能感兴趣的:(Django+Ubuntu web开发验证码插件配置)