django>2.0
django-simple-captcha
安装django-simple-captcha
GitHub:https://github.com/mbi/django-simple-captcha
doc:https://django-simple-captcha.readthedocs.io/en/latest/
配置
-
settings.py
Addcaptcha
to theINSTALLED_APPS
in yoursettings.py
-
urls.py
path(‘captcha/’, include(‘captcha.urls’)),
执行makemigration,migrate
会生成这样的表
在form中写验证表单
class RegisterForm(forms.Form):
email = forms.EmailField(required=True)
password = forms.CharField(required=True, min_length=5)
captcha = CaptchaField(error_messages={"invalid":"验证码错误"})
在前端模板应用
在form的属于验证码的地方:
{{ register_form.captcha }}