0 votes
1 view
in Web Technology by (19.9k points)

I'm having the following error

Reverse for 'vote' with arguments '(2,)' not found. 1 pattern(s) tried: ['enquete\/\

This is the traceback I'm having

Internal Server Error: /enquete/2/

Traceback (most recent call last):

  File "/home/johnl/.local/lib/python3.6/site-packages/django/core/handlers/exception.py", line 34, in inner

    response = get_response(request)

  File "/home/johnl/.local/lib/python3.6/site-packages/django/core/handlers/base.py", line 156, in _get_response

    response = self.process_exception_by_middleware(e, request)

  File "/home/johnl/.local/lib/python3.6/site-packages/django/core/handlers/base.py", line 154, in _get_response

    response = response.render()

  File "/home/johnl/.local/lib/python3.6/site-packages/django/template/response.py", line 106, in render

    self.content = self.rendered_content

  File "/home/johnl/.local/lib/python3.6/site-packages/django/template/response.py", line 83, in rendered_content

    content = template.render(context, self._request)

  File "/home/johnl/.local/lib/python3.6/site-packages/django/template/backends/django.py", line 61, in render

    return self.template.render(context)

  File "/home/johnl/.local/lib/python3.6/site-packages/django/template/base.py", line 171, in render

    return self._render(context)

  File "/home/johnl/.local/lib/python3.6/site-packages/django/template/base.py", line 163, in _render

    return self.nodelist.render(context)

  File "/home/johnl/.local/lib/python3.6/site-packages/django/template/base.py", line 937, in render

    bit = node.render_annotated(context)

  File "/home/johnl/.local/lib/python3.6/site-packages/django/template/base.py", line 904, in render_annotated

    return self.render(context)

  File "/home/johnl/.local/lib/python3.6/site-packages/django/template/defaulttags.py", line 442, in render

    url = reverse(view_name, args=args, kwargs=kwargs, current_app=current_app)

  File "/home/johnl/.local/lib/python3.6/site-packages/django/urls/base.py", line 90, in reverse

    return iri_to_uri(resolver._reverse_with_prefix(view, prefix, *args, **kwargs))

  File "/home/johnl/.local/lib/python3.6/site-packages/django/urls/resolvers.py", line 622, in _reverse_with_prefix

    raise NoReverseMatch(msg)

django.urls.exceptions.NoReverseMatch: Reverse for 'vote' with arguments '(2,)' not found. 1 pattern(s) tried: ['enquete\\/\\<int\\:question_id\\/vote\\/$']

[02/Mar/2019 17:18:39] "GET /enquete/2/ HTTP/1.1" 500 112049

^C%  

This is my view, view.py

 class DetailView(generic.DetailView):

      model = Question

      template_name = 'enquete/detail.html'

This is my URL, url.py

  app_name = 'enquete'

  urlpatterns = [

      path('',views.IndexView.as_view(), name='index'),

      path('<int:pk>/',views.DetailView.as_view(),name='detail'),

      path('<int:pk>/results',views.ResultsView.as_view(),name='results'),

      path('<int:question_id/vote/',views.vote,name='vote'),

 ]

This is my template, detail.html

<h1> {{ question.question_text }} </h1>

{% if error_message %}<p><strong>{{ error_message }}</strong></p>{% endif %}

<form action="{% url 'enquete:vote' question.id %}" method="get">

{% csrf_token %}

{% for choice in question.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>

Do I need to add vote in my model? if yes, how. I'm quite dumbfounded on what I should do next.

1 Answer

0 votes
by (25.1k points)

You have wrong url path, please correct as below. Missplaced '>'

path('<int:question_id>/vote/',views.vote,name='vote'),

Welcome to Intellipaat Community. Get your technical queries answered by top developers !


Categories

...