美文网首页django-game
captcha包 验证码 使用介绍

captcha包 验证码 使用介绍

作者: 你常不走的路 | 来源:发表于2018-01-20 14:11 被阅读173次

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

    安装

    pip install  django-simple-captcha
    

    settings 配置

    INSTALLED_APPS = [
        ...
        'captcha',
    ]
    

    进行migrate 生成表

    在form中使用 验证码字段

    from django import forms
    from captcha.fields import CaptchaField
    
    class CaptchaTestForm(forms.Form):
        ...
        captcha = CaptchaField()
    

    在modelform中使用

    from django import forms
    from captcha.fields import CaptchaField
    
    class CaptchaTestModelForm(forms.ModelForm):
        captcha = CaptchaField()
        class Meta:
            model = MyModel
    

    html添加验证码字段

    <label>验&nbsp;证&nbsp;码</label>
           {{ 你的form.captcha }}
    

    这样就可以了

    相关文章

      网友评论

        本文标题:captcha包 验证码 使用介绍

        本文链接:https://www.haomeiwen.com/subject/tlktaxtx.html