I am in the middle of tutorial 4, but am getting an error.
What did I do wrong?

NoReverseMatch at /polls/3/vote/ 

Reverse for 'results' with arguments '(3L,)' and keyword arguments '{}' not 
found. 1 pattern(s) tried: [u'polls/(lP<question_id>\\d+)/results/$']

 Request Method: POST  Request URL: 
http://www.alzacloud.net:8000/polls/3/vote/  Django Version: 1.7.1  Exception 
Type: NoReverseMatch  Exception Value: 

Reverse for 'results' with arguments '(3L,)' and keyword arguments '{}' not 
found. 1 pattern(s) tried: [u'polls/(lP<question_id>\\d+)/results/$']

 Exception Location: 
/home/terryl/cloud/local/lib/python2.7/site-packages/django/core/urlresolvers.py
 
in _reverse_with_prefix, line 468  Python Executable: 
/home/terryl/cloud/bin/python  Python Version: 2.7.6  Python Path: 

['/home/terryl/pjtcloud',
 '/home/terryl/cloud/lib/python2.7',
 '/home/terryl/cloud/lib/python2.7/plat-x86_64-linux-gnu',
 '/home/terryl/cloud/lib/python2.7/lib-tk',
 '/home/terryl/cloud/lib/python2.7/lib-old',
 '/home/terryl/cloud/lib/python2.7/lib-dynload',
 '/usr/lib/python2.7',
 '/usr/lib/python2.7/plat-x86_64-linux-gnu',
 '/usr/lib/python2.7/lib-tk',
 '/home/terryl/cloud/local/lib/python2.7/site-packages',
 '/home/terryl/cloud/lib/python2.7/site-packages']


polls/urls.py

from django.conf.urls import patterns, include, url
from django.contrib import admin
from polls import views

#urlpatterns = patterns('',
#    url(r'^polls/', include('polls.urls')),
#    url(r'^admin/', include(admin.site.urls)),
#)

    # ex: /polls/
    # ex: /polls/5/
    # ex: /polls/5/results/
    # ex: /polls/5/vote/
urlpatterns = patterns('',
    url(r'^$', views.index, name='index'),
    url(r'^(?P<question_id>\d+)/$', views.detail, name='detail'),
    url(r'^(lP<question_id>\d+)/results/$', views.results, name='results'),
    url(r'^(?P<question_id>\d+)/vote/$', views.vote, name='vote'),
)


polls/views.py

from django.shortcuts import get_object_or_404, renderfrom django.http import 
HttpResponseRedirect, HttpResponsefrom django.core.urlresolvers import reverse
from polls.models import Choice, Question# ...def vote(request, question_id):
    p = get_object_or_404(Question, pk=question_id)
    try:
        selected_choice = p.choice_set.get(pk=request.POST['choice'])
    except (KeyError, Choice.DoesNotExist):
        # Redisplay the question voting form.
        return render(request, 'polls/detail.html', {
            'question': 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,)))


-- 
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+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
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/3995d3d9-63b9-4cb4-ab65-49c85e8c8b87%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to