Python code snippet – How to add captcha in django forms

This is simple:

1. Install the django-recaptcha plugin and follow the instructions. You will need the following vars and classes:

RECAPTCHA_KEY_PUBLIC = 'public-key'
RECAPTCHA_KEY_PRIVATE = 'private-key'
NOCAPTCHA = True

Now you’re ready to add the captcha to your form:

from django import forms
from django.conf import settingsfrom captcha.fields import ReCaptchaField

class ReCAPTCHAForm(forms.Form):
captcha = ReCaptchaField()

That’s all there is to it!