Monday, August 27th, 2012

A Django petition app

I have just recently released on my bitbucket account, a super simple django-petition app. It should work easily with most existing Django projects. This post will explain how to get it up and running as quickly as possible.

First you will need to confirm your Django project to send out Email via SMTP, so that pledges can receive their confirmation email. Once you have this configured, you will need to add a few extra things to your settings.py:

TEMPLATE_CONTEXT_PROCESSORS = (
    ....
    'petition.context_processors.petition_form',
)

INSTALLED_APPS = (
   ....
    'south',    # Recommended but not required.
    'petition',
)

# Example email configuration to work with a Google Mail account
EMAIL_BACKEND = 'django.core.mail.backends.smtp.EmailBackend'
EMAIL_HOST = 'smtp.gmail.com'
EMAIL_PORT = 587
EMAIL_HOST_USER = 'Your Gmail account'
EMAIL_HOST_PASSWORD = '**password**'
EMAIL_USE_TLS = True

PETITION_FROM = EMAIL_HOST_USER # You can change this to any email address.

From within your templates, you will have access special context variables: petition_form and pledge_count. If your site is not solely a petition website, I would not recommend using the petition context as every request it will count how many have signed the petition. This context is mainly used with a site-wide template to display the amount of signatures. The petition_form is there to make it easier to add the form anywhere, or in a global position for a petition-only site.

You should customize the templates to suit your petition's particular theme. You should override them using the standard Django method, using the global templates directory for the project, and creating a directory in there called petition.

It is highly recommended to use south, if you plan on updating your local app to use new and exciting features which may become available in this project in the future.

About Me

My Photo
Names Kevin, hugely into UNIX technologies, not just Linux. I've dabbled with the demons, played with the Sun, and now with the Penguins.




Kevin Veroneau Consulting Services
Do you require the services of a Django contractor? Do you need both a website and hosting services? Perhaps I can help.

If you like what you read, please consider donating to help with hosting costs, and to fund future books to review.

Python Powered | © 2012-2013 Kevin Veroneau