Works on Django 1.3, not tested on previous version but is very likely to work.

jQuery, including AJAX functions



Create the poll item, including question and answers.

Poll submission

Record a poll submission containing the answer id and text. Each record belongs to a poll (using a ForeignKey)


A function to download a CSV file containing the poll result has been written.

The view that create this CSV is in (called: export_answers).

Template tags

In templatetags/, a function called get_polls renders all the active polls. An argument called limit controls the number of poll returned, by default, it is set to 2.

The form is rendered using the polls.html template.

This template containg the JQuery call to make the AJAX request which submit the result.

* Please note that JQuery must be pre-included in your page template.

AJAX view

The submission is controlled by the submit button, which triggers an AJAX call.

The URL of the call is: /poll/submit/(poll_id)/(answer_id)

This URL will submit the answer and return an HTML view which is re-loaded by JQUERY in to the poll form area.

Bar graph

A simple bar graph is generated from the answer results. It is a pro-rata of the highest value by the width of the box containing the graph.

In, poll model enter the relevant size:

#Enter the div of the width containing the bar graph
div_width = 200


First of all, you must create a new Django project if you don't have one already and run through the conventional installation procedure (settings, db, etc...), then:

1. Download the django-ajax-poll app
2. Add it to your app list in

3. Add poll to the main
	urlpatterns = patterns('',
	    url(r'^poll/', include('myproject.poll.urls')),
* Please note: I have called my Django project gpoll in various area of the app, so may have to change this reference for your Django project. 

4. Browse to localhost:8000/poll (if you're on local obviously, otherwise use your root domain)

HTML tags

The list of polls need to be implementd as follow:

{% load poll_tags %}
<div id="poll">{% get_polls %}</div>    

Which will render the template polls.html

The AJAX submission will save the result and render the template poll_answer_ajax.html

default.html is an example page rendering the polls all together.

Possible errors

"CSRF token missing or incorrect"

Disable csrf middleware


Version working with CSRF has not been created yet.