验证码

在github中搜验证码,那个有使用文档

# pip install django-simple-captcha==0.4.6

# setting app
captcha

# url
url(r'^captcha/', include('captcha.urls')),

# 运用migration 和 migrate生成验证码的表

# forms一个验证form类的字段
# 异常字典中这个字段是固定的
captcha = CaptchaField(error_messages={'invalid': u'验证码错误'})

# html中在验证码的范围内写
<label>验&nbsp;证&nbsp;码</label>
 {{ register_form.captcha }}

# view 
    def get(self, request):
        register_form = RegisterForm()
        return render(request, 'register.html', {'register_form':register_form})


posted on 2017-06-05 09:22  NeedEnjoyLife  阅读(234)  评论(0编辑  收藏  举报