NoReverseMatch at /polls/1/vote/
Reverse for 'results' with arguments '(1,)' not found. 1 pattern(s) tried: ['polls\\/\\<int\\:pk\\/results\\/$']
Request Method: POST Request URL: http://127.0.0.1:8000/polls/1/vote/ Django Version: 2.0.6 Exception Type: NoReverseMatch Exception Value: Reverse for 'results' with arguments '(1,)' not found. 1 pattern(s) tried: ['polls\\/\\<int\\:pk\\/results\\/$']Exception Location: C:\Users\pwalker\AppData\Local\Programs\Python\Python36-32\lib\site-packages\django\urls\resolvers.py in _reverse_with_prefix, line 636 Python Executable: C:\Users\pwalker\AppData\Local\Programs\Python\Python36-32\python.exe Python Version: 3.6.4 Python Path: ['C:\\Users\\pwalker\\Coding\\Python-Practice\\Gaining_Agreement\\GA_site', 'C:\\Users\\pwalker\\AppData\\Local\\Programs\\Python\\Python36-32\\python36.zip', 'C:\\Users\\pwalker\\AppData\\Local\\Programs\\Python\\Python36-32\\DLLs', 'C:\\Users\\pwalker\\AppData\\Local\\Programs\\Python\\Python36-32\\lib', 'C:\\Users\\pwalker\\AppData\\Local\\Programs\\Python\\Python36-32', 'C:\\Users\\pwalker\\AppData\\Local\\Programs\\Python\\Python36-32\\lib\\site-packages']
...
def vote(request, question_id): question = get_object_or_404(Question, pk=question_id) try: selected_choice = question.choice_set.get(pk=request.POST['choice']) except (KeyError, Choice.DoesNotExist): # Redisplay the question voting formself. return render(request, 'polls/detail.html', {'question': question, '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 buttonself. return HttpResponseRedirect(reverse('polls:results', args=(question.id,)))
urlpatterns = [ # ex: /polls/ path('', views.IndexView.as_view(), name='index'), # ex: /polls/5/ # the 'name' value as called by the {% url %} template tag path('<int:pk>/', views.DetailView.as_view(), name='detail'), # ex: /polls/5/results/ path('<int:pk/results/', views.ResultsView.as_view(), name='results'), # ex: /polls/5/vote/ path('<int:question_id>/vote/', views.vote, name='vote'),]
<h1>{{ question.question_text }}</h1>
<ul>{% for choice in question.choice_set.all %} <li>{{ choice.choice_text }} -- {{ choice.votes }} vote{{ choice.votes|pluralize }}</li>{% endfor %}</ul>
<a href="{% url 'polls:detail' question.id %}">Vote again?</a>
path('<int:pk/results/', views.ResultsView.as_view(), name='results'),
Should be
path('<int:pk>/results/', views.ResultsView.as_view(), name='results'),
--
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+unsubscribe@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/38f2f492-86a3-47e6-9652-cf9a8e858ad6%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
It looks like you have a typo:
urlpatterns = [
# ex: /polls/
path('', views.IndexView.as_view(), name='index'),
# ex: /polls/5/
# the 'name' value as called by the {% url %} template tag
path('<int:pk>/', views.DetailView.as_view(), name='detail'),
# ex: /polls/5/results/
path('<int:pk/results/', views.ResultsView.as_view(), name='results'),
# ex: /polls/5/vote/
path('<int:question_id>/vote/', views.vote, name='vote'),
]
The red line should probably have this path:
<int:pk>/results/
--
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 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/38f2f492-86a3-47e6-9652-cf9a8e858ad6%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
--
You received this message because you are subscribed to a topic in the Google Groups "Django users" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/django-users/haz9iF_HDpc/unsubscribe.
To unsubscribe from this group and all its topics, 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/CAHtg44BU4iM0%3Dy0EqaToAm6Y1jnRt14uCG9sL_6gJsEjwWy_sg%40mail.gmail.com.
--
You received this message because you are subscribed to a topic in the Google Groups "Django users" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/django-users/haz9iF_HDpc/unsubscribe.
To unsubscribe from this group and all its topics, 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/2626313.Z6rRR89q5h%40fritzbook.