It's the second time this issue appears in the list in two weeks, maybe it's time to recheck the tutorial?
There's no "polls" in your results' url, doesn't the tutorial say you should have two urls file? one in project/urls.py and another one in polls/urls.py ? the polls-specific urls shouldn't start with "^polls/" and be in polls/urls.py, and in project/urls.py there should be a line with url(r'^polls/', include('polls.urls')), On Mon, Jul 16, 2012 at 1:59 PM, Bill Torcaso <b...@billtorcaso.org> wrote: > > Django is great, and the tutorial is great. I'm having a problem at the > very end of tutorial-4. > > I try to use generic views, and I get an error when I Redirect from the > POST request in vote() to the Results page. Details below. > > The tutorial code says to put this in my urls.py: > > url(r'^(?P<pk>\d+)/results/$', > DetailView.as_view( > model=Poll, > template_name='polls/results.html') > ,name="poll_results" > ), > > And this in my views.py: > > from django.shortcuts import get_object_or_404, render_to_response > from django.http import HttpResponseRedirect, HttpResponse > from django.core.urlresolvers import reverse > from django.template import RequestContext > from polls.models import Choice, Poll > > > 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_to_response('polls/detail.html', { > 'poll': p, > 'error_message': "You didn't select a choice.", > }, context_instance=RequestContext(request)) > 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 > ,))) > ### OKAY: return HttpResponseRedirect("/polls/%i/results" % > p.id) > ### OKAY: return render_to_response("polls/results.html", > {"poll": p}) > ### BAD: return > HttpResponseRedirect(reverse('polls.views.results', args=(p.id,))) > > > > NoReverseMatch at /polls/4/vote/ > > Reverse for 'polls_results' with arguments '(4,)' and keyword arguments > '{}' not found. > > *Request Method:* > > POST > > *Request URL:* > > http://127.0.0.1:8000/polls/4/vote/ > > *Django Version:* > > 1.4 > > *Exception Type:* > > NoReverseMatch > > *Exception Value:* > > Reverse for 'polls_results' with arguments '(4,)' and keyword arguments > '{}' not found. > > *Exception Location:* > > /Library/Python/2.7/site-packages/django/core/urlresolvers.py in > _reverse_with_prefix, line 407 > > *Python Executable:* > > /usr/bin/python > > *Python Version:* > > 2.7.1 > > *Python Path:* > > ['/Users/s3/Desktop/CODE/APPSS3/EdAssistant/experiments/djtest', > > > > '/Library/Python/2.7/site-packages/mercurial-2.0.2-py2.7-macosx-10.7-intel.egg', > > > '/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python27.zip', > > '/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7', > > > > '/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/plat-darwin', > > > > '/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/plat-mac', > > > > '/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/plat-mac/lib-scriptpackages', > > > '/System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python', > > > > '/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/lib-tk', > > > > '/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/lib-old', > > > > '/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/lib-dynload', > > > > '/System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python/PyObjC', > > '/Library/Python/2.7/site-packages'] > > *Server time:* > > Mon, 16 Jul 2012 11:53:21 -0500 > > -- > You received this message because you are subscribed to the Google Groups > "Django users" group. > To view this discussion on the web visit > https://groups.google.com/d/msg/django-users/-/f-sjN1OtNuwJ. > To post to this group, send email to django-users@googlegroups.com. > To unsubscribe from this group, send email to > django-users+unsubscr...@googlegroups.com. > For more options, visit this group at > http://groups.google.com/group/django-users?hl=en. > -- "The whole of Japan is pure invention. There is no such country, there are no such people" --Oscar Wilde |_|0|_| |_|_|0| |0|0|0| (\__/) (='.'=)This is Bunny. Copy and paste bunny (")_(") to help him gain world domination. -- You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com. To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/django-users?hl=en.