Django Contact Form with reCAPTCHA

The app is a very basic contact form for Django 1.4. It simply allows users to send a message to email addresses specified in

This is how the form can be extended with django-recaptcha to add a reCAPTCHA field to the form.

Both and django-recaptcha can be installed using pip.

pip install django-recaptcha

They both need to be in INSTALLED_APPS.

    # ... 
    # ... 

The public and private key obtained from reCAPTCHA are specified in

RECAPTCHA_PUBLIC_KEY = 'YOUR reCAPTCHA public key goes here'
RECAPTCHA_PRIVATE_KEY = 'YOUR reCAPTCHA private key goes here'

The email recipient(s) for the contact form are specified in


By default, the built-in contact form is used. However, a custom form can be specified in

CONTACT_FORM_CLASS = 'myproject.forms.ReCaptchaContactForm'

The ReCaptchaContactForm should extend and add the ReCaptchaField.


from import ContactForm
from captcha.fields import ReCaptchaField

class ReCaptchaContactForm(ContactForm):
    captcha = ReCaptchaField()

You can see this in action on my contact form

This works for other fields too. You could use an "Are you human?" field instead of reCAPTCHA or whatever suits your needs.

Did you enjoy Django Contact Form with reCAPTCHA? If you would like to help support my work, A donation of a buck or two would be very much appreciated.
blog comments powered by Disqus
Linux Servers on the Cloud IN MINUTES