Patrick Beeson

How to install django-contact-form

Entry updated Aug. 12, 2008 at 7:09 a.m.

A renewed vigor for completing an upcoming Web project has me back on the Django-crack again. And with that impetus, I've successfully installed and implemented James Bennett's excellent django-contact-form app.

But it wasn't easy for a Python/Django noob like myself. So here's a quick guide -- much of this is adapted from the overview text file included with the application -- on getting it working for your Django install.

This should at least save you an hour or two doing Google searches or browsing the Django Users Google Group.

Note: My Django instance is installed on cheap Dreamhost shared hosting. Your mileage may vary.

Do a Subversion checkout of the latest version on your Python path. You can grab this from the project's home on Google Code.

Add "contact_form" to your settings.py file under "installed_apps". I placed the contact-form app outside of the project I intended to use it with so it could be used with other projects.

Add the following to your project's urls.py file:

(r'^contact/', include('contact_form.urls')),

Create three templates for the contact form:

  • contact_form/contact_form.txt
  • contact_form/contact_form.html
  • contact_form/contact_form_sent.html

On the "contact_form.txt" template, use the following Django tags (for the sender's name, email and message, respectively):

{{ name}}
{{ email }}
{{ body }}

The actual contact form will be generated using Django's newforms library. For instance, I used the following markup and Django tags to produce a basic form (you need to add the "form" tags) with a series of "p" tags:

{{ form.as_p }}

The final template can be as simple as "You've sent me an e-mail" or something to that effect.

You may need to adjust a few items in your core Django settings.py file to receive e-mail from clients such as Google. I added the following lines to my project's settings.py file:

EMAIL_HOST = 'smtp.gmail.com'
EMAIL_HOST_USER = 'emailname@gmail.com'
EMAIL_HOST_PASSWORD = 'yourpassword'
EMAIL_USE_TLS = True

You should now be able to visit http://sitename.com/contact/ and view your contact form as well as send a basic message to yourself.

Those of you wanting greater flexibility would do best to explore the django-contact-form's documentation in more detail. I simply wanted a basic contact form for a Django project.

If you are having trouble following these directions or simply have a question about my application install please post a comment here or send me a message using the contact form.

UPDATE: (8/12/08) I fixed a missing parenthesis in the URL configuration cited above, thanks to a email from a reader. Thanks!

No comments

Comments are closed for this entry.

Author details

Patrick Beeson

Want to learn more? Visit my about section or send me a message.

Latest photo on Flickr

Patrick Beeson posted a photo:

Now drinking: Fullsteam First Frost