• 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

      

  • 相关阅读:
    解决docker pull很慢的方法
    Linux 基础 Day1
    linux运维人员必须熟悉的运维工具汇总
    chrome 浏览器插件推荐
    只能运维主要职责
    Linux查看所有用户用命令
    ubuntu16.04 离线包安装docker
    2013-10
    ELK原理与介绍
    shell中各种括号的作用()、(())、[]、[[]]、{}
  • 原文地址:https://www.cnblogs.com/2bjiujiu/p/7452778.html
Copyright © 2020-2023  润新知