利用插件captcha生成验证码注册capatcha:pipinstalldjango-simple-captcha0.4.6在setting.py中的INSTALL 利用插件captcha生成验证码 注册capatcha: pip install django-simple-captcha==0.4.6 在setting.py中的INSTALLED_APPS中
利用插件captcha生成验证码
注册capatcha:
pip install django-simple-captcha==0.4.6在setting.py中的INSTALLED_APPS中增加’capatcha’
在form.py中写入:
from captcha.fields import CaptchaFieldclass RegisterForm(forms.Form): email = forms.CharField(required=True) password = forms.CharField(required=True, min_length=5) captcha = CaptchaField(error_messages={"invalid":u"验证码错误"})在views.py 中写入:
class RegisterView(View): def get(self, request): register_form = RegisterForm(request.POST) return render(request, "register.html", {'register_form':register_form})register.html 加入{{ register_form.captcha }} 运行makemigrations 、migrate 更新数据库 效果如下: 
