I am trying to create the project described by the Django Tutorials. However, I have reached a problem that I am stuck on after implementing the voting forms described in tutorial 4 (
https://docs.djangoproject.com/en/1.6/intro/tutorial04/). When I run my website and go to the url:
http://localhost:8000/polls/1/vote/, I am greeted with an exception:
NoReverseMatch at /polls/1/vote/
value: u'polls' is not a registered namespace
here is templates/polls/detail.html:
<h1>{{ poll.question }}</h1>
{% if error_message %}<p><strong>{{ error_message }}</strong></p>{% endif %}
<form action="{% url 'polls:vote'
poll.id %}" method="post">
<<Exception occurs on this line{% for choice in poll.choice_set.all %}
<input type="radio" name="choice" id="choice{{ forloop.counter }}" value="{{
choice.id }}" />
<label for="choice{{ forloop.counter }}">{{ choice.choice_text }}</label><br />
<input type="submit" value="Vote" />
This template is rendered from this view in polls/views.py:
def vote(request, poll_id):
p = get_object_or_404(Poll, pk=poll_id)
selected_choice = p.choice_set.get(pk=request.POST['choice'])
except (KeyError, Choice.DoesNotExist):
# Redisplay the poll voting form.
return render(request, 'polls/detail.html', {
'error_message': "You didn't select a choice.",
selected_choice.votes += 1
# Always return an HttpResponseRedirect after successfully dealing
# with POST data. This prevents data from being posted twice if a
# user hits the Back button.
return HttpResponseRedirect(reverse('polls:results', args=(
p.id,)))
It seems strange that 'polls' is not a registered namespace because it is the name of my django application. Any ideas as to what I could be doing wrong here?