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
{% csrf_token %}
{% 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 />
{% endfor %}
<input type="submit" value="Vote" />
</form>
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)
try:
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', {
'poll': p,
'error_message': "You didn't select a choice.",
})
else:
selected_choice.votes += 1
selected_choice.save()
# 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?
--
You received this message because you are subscribed to the Google Groups
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/django-users.
To view this discussion on the web visit
https://groups.google.com/d/msgid/django-users/c8050fdc-38eb-43ed-b77a-ee5a2c872509%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.