当前位置 : 主页 > 网络编程 > 其它编程 >

注册后台逻辑一

来源:互联网 收集:自由互联 发布时间:2023-07-02
利用插件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:pipinstalldjango-simple-captcha0.4.6在setting.py中的INSTALL

利用插件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 更新数据库 效果如下: 这里写图片描述

【文章原创作者:武汉网站设计 http://www.1234xp.com/wuhan.html 复制请保留原URL】
上一篇:Scrapy案例02-腾讯招聘信息爬取
下一篇:没有了
网友评论