Django captcha contact form

This project is an example to show how to combine contact forms and captcha protection in Django.

To not reinvent the wheel everytime, the project relies on Django contact form and Django Simple Captcha , which in turn requires Python Image Library to generate captcha images. Both the applications are well focused on their specific goals, but also flexible enough to be used together with interesting results.

Linux installation

To see captcha forms in action you need an internet connection, virtualenv and optionally mercurial. There are very good reasons to use virtualenv; if you don't yet use it consider to start now, you'll be rewarded.

Create a virtual environment and activate it:

$ virtualenv captcha_contact_form
$ cd captcha_contact_form
$ . bin/activate

If mercurial is installed get the project source:

$ hg clone ssh:// project

If mercurial is not installed download and extract tarball files:

$ wget
$ tar xzf tip.tar.gz
$ # rename the extracted directory to project, for example:
$ mv pdina-django-captcha-contact-form-d72850994a9f project

Install the required packages:

$ pip install -r project/requirements.txt

Create the database and run the web server:

$ cd project
$ python syncdb --no-input
$ python runserver

Visit and see the captcha form working.

The setting EMAIL_BACKEND = 'django.core.mail.backends.console.EmailBackend' prevents any mail to be really sent. Instead mails get written to standard out (the console running the development web server).

Final notes and credits

This project is one of many possible starting points to get forms and captchas working together. Django Simple Captcha and Django contact form are easily customizable, just read their docs and do exactly what you need.