Django Tutorials: NoReverseMatch at /polls/1/vote/

724 views
Skip to first unread message

wasingej

unread,
Mar 20, 2014, 7:07:47 PM3/20/14
to django...@googlegroups.com
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?

Daniel Roseman

unread,
Mar 21, 2014, 5:01:29 AM3/21/14
to django...@googlegroups.com
On Thursday, 20 March 2014 23:07:47 UTC, wasingej wrote:
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

<snip>

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?

Are you sure you've followed the instructions at the end of the previous part?
--
DR. 

odoote...@gmail.com

unread,
Feb 21, 2019, 6:32:43 AM2/21/19
to Django users
please let me know the particular solution for version 2.1 i m stucked

Suresh Kannan

unread,
Feb 21, 2019, 10:38:06 AM2/21/19
to django...@googlegroups.com

--
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 django-users...@googlegroups.com.
To post to this group, send email to django...@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/274e59fa-fd4c-4535-afc7-dea30195ddc6%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Victor H. Velasquez Rizo

unread,
Feb 21, 2019, 6:03:39 PM2/21/19
to django...@googlegroups.com
Daniel
Share your urls.py file....

--
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 django-users...@googlegroups.com.
To post to this group, send email to django...@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/274e59fa-fd4c-4535-afc7-dea30195ddc6%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


--



Atte...,.
Vìctor Hugo Velàsquez Rizo
Cali - Colombia
Reply all
Reply to author
Forward
0 new messages