您的位置:首页 > 编程语言 > Go语言

django验证码模块 DjangoVerifyCode

2013-05-06 23:23 239 查看
1.下载:git clone https://github.com/tianyu0915/DjangoVerifyCode.git
2. cd $dir;python setup.py install

显示验证码(views.py)

from DjangoVerifyCode import Code
def code(request):
code =  Code(request)
code.worlds = ['hello','world','helloworld']
#code.type = 'world'
code.type = 'number'
return code.display()

检查用户输入的验证码是否正确(views.py)

from DjangoVerifyCode import Code
def index(request):
_code = request.GET.get('code') or ''
if not _code:
return render('index.html',locals())

code = Code(request)
if code.check(_code):
return HttpResponse('验证成功')
else:
return HttpResponse('验证失败')

自定义

用户可根据自己的需要对DjangoVerifyCode.Code对象的属性进行设置

输出图片的宽度
code.img_width
= 150

输出图片的高度
code.img_height
= 30

设置验证码类型('number'/'world')
code.type = 'number'


依赖

PIL
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: