在django中生成英文单词验证码,提供验证码图片生成,检查验证码等功能.
pip install DjangoVerifyCode or easy_install DjangoVerifyCode
from DjangoVerifyCode import Code def code(request): code = Code(request) return code.display()
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
code.font_color = [‘black’,’darkblue’,’darkred’]
font_size = 24