在django中生成英文单词验证码,提供验证码图片生成,检查验证码等功能 原用于pythoner.net的验证码,现整理出来打包发布到pypi.
pip install DjangoCaptcha or easy_install DjangoCaptcha
from DjangoCaptcha import Captcha def code(request): ca = Captcha(request) ca.words = ['hello','world','helloworld'] ca.type = 'number' return ca.display()
from DjangoCaptcha import Captcha def index(request): _code = request.GET.get('code') or '' if not _code: return render('index.html',locals()) ca = Captcha(request) if ca.check(_code): return HttpResponse('验证成功') else: return HttpResponse('验证失败')
ca.img_width = 150
image
ca.img_height = 30
numberword)type fo code (‘number’/’word’)
ca.type = ‘number’