zoukankan      html  css  js  c++  java
  • 利用django-simple-captcha生成验证码

    参考文档

    http://django-simple-captcha.readthedocs.io/en/latest/

    django支持1.7+

    1.安装

    pip install  django-simple-captcha
    

    2.添加到install_apps中

    3.添加以下url到urls文件中

    from django.conf.urls import url,include
    url(r'^captcha/', include('captcha.urls')),    #添加到url
    

    4.生成数据库

    makemigrations
    migrate
    

    5.应用配置

    1. 在forms.py中导入以下模块
    from captcha.fields import CaptchaField
    在下关Forms中使用
    class RegisterForm(forms.Form):
        email = forms.EmailField(required=True)
        password = forms.CharField(required=True,min_length=5)
        captcha = CaptchaField(error_messages={'invalid':u'验证码错误'})
    
    1. 在views.py中使用forms
    class RegisterView(View):
        def get(self,request):
            register_form = RegisterForm()
            return render(request,'register.html',{'register_form':register_form})
     
        def post(self,request):
            register_form = RegisterForm()
            if register_form.is_valid():
                user_name = request.POST.get("username", '')
                pass_word = request.POST.get("password", '')
                user_profile = UserProfile()
                user_profile.username = user_name
                user_profile.email = user_name
                user_profile.password = make_password(pass_word)
                user_profile.save()
    

    6.前端渲染即可

    image

  • 相关阅读:
    HTML if条件注释解读
    Springboot整合logback日志系统
    Springboot @Valid 参数校验
    JDK1.8 版的if else
    Android获取手机定位坐标
    CentOS8安装JDK
    Vue全局配置文件
    git学习
    百度前端面试题—基础
    前端知识网络
  • 原文地址:https://www.cnblogs.com/guigujun/p/8515190.html
Copyright © 2011-2022 走看看