开发者

Implement Django Simple Captcha with the existing django.contrib.auth.forms

I would like to add captcha on my django registration form using Django Simple Captcha found here: http://code.google.com/p/django-simple-captcha/

This works great if you create a new form but I'm using the django.contrib.auth.forms the one that comes with django. Any idea开发者_Go百科 how I might be able to implement captcha with the existing django auth views? Thank you!


You could simply subclass the django.contrib.auth.forms forms and add a CaptchaField, like this:

from django.contrib.auth.forms import UserCreationForm
from captcha.fields import CaptchaField

class CaptchaUserCreationForm(UserCreationForm):
    captcha = CaptchaField()

and use the new Form in your view as usual:

if request.POST:
    form = CaptchaUserCreationForm(request.POST)
    if form.is_valid():
        return HttpResponseRedirect('/?ok')
else:
    form = CaptchaUserCreationForm()
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜