Django_验证码

问题:

  登录、注册、忘记密码时候,提交用户数据时候,需要用到用户填写验证码,如何生成验证码?

那,解决方法?

  1. 第三方模块 django-simple-captcha
    pip install django-simple-captcha
  2. 把 captcha 添加到app中
    INSTALLED_APPS = [
        ...
        'captcha',
    ]
  3. 写form验证时候,把这个字段添加进去
    class ForgetForm(forms.Form):
        email = forms.EmailField(required=True, error_messages={'required': u'邮箱不能为空'})
        # 验证码验证
        captcha = CaptchaField(error_messages={'invalid': u'验证码错误', 'required': u'验证码不能为空'})
  4. 写view时候,实例化form,把对象传递给模版
    class ForgetView(View):
        """发送重置密码邮箱验证"""
        def get(self, request):
            forget_form = ForgetForm()
            return render(request, 'forgetpwd.html', {'forget_form': forget_form})
  5. 写template时候,.captcha获得验证码功能,并支持点击刷新验证码
    < divclass ="form-group captcha1 marb38" >
    <label>验 & nbsp;证 & nbsp;码</label >
    
        {{forget_form.captcha}}
        
    </div>
    

    Githup地址:https://github.com/mbi/django-simple-captcha

 

 

  

转载于:https://www.cnblogs.com/2bjiujiu/p/7452778.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值