NoReverseMatch at /polls/ Reverse for 'vote' with arguments '('',)' not found. 1 pattern(s) tried: ['polls/(?P<question_id>[0-9]+)/vote/\\Z']

I keep getting this error. can you please help?

### Reverse for ‘vote’ with arguments ‘(’‘,)’ not found. 1 pattern(s) tried: \[‘polls/(?P<question_id>\[0-9\]+)/vote/\\Z’\]

2	{% if latest_question_list %}
3	
4	        {% for question in latest_question_list %}
5	            [ {{ question.question_text}}](/polls/%7B%7Bquestion.id%7D%7D/)
6	        {% endfor %}
7	
8	{% else %}
9	     No polls are vailable.
10	{% endif%}
11	
12

urls.py

from django.urls import path
from . import views
app_name = “polls”

urlpatterns = \[
path("", views.index, name="index"),
path("<int:question_id>/", views.detail, name="detail"),
path("<int:question_id>/results/", views.results, name="results"),
path("<int:question_id>/vote/", views.vote, name="vote"),
\]

detail.html

{form action=“{% url ‘polls:vote’ question.id %}” method=“post”}

{% csrf_token %}

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

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

{% 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%}


</fieldset>

<input type="submit" value="Vote">

</form>

Welcome @nsateesh9 !

Side Note: When posting code here, enclose the complete block of code between lines of three backtick - ` characters. This means you’ll have a line of ```, then your code, then another line of ```. This forces the forum software to keep your code properly formatted. (I have taken the liberty of correcting your original post.
Please remember to do this in the future.)

Also, when you’re posting an error, please post the error message from the server console. Do not copy/paste the error message being shown in the browser.

Please post the view.

Thanks for quick response.

def vote(request, question_id):
    #return HttpResponse("You're voting on question %s." % 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 voiting form
        return render(
            request,
            "polls/detail.html",
            {
                "question": question,
                "error_message" : "You didnt select a choice.",
            },
        )
    else:
        selected_choice.votes = F("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 = (question.id,)))
```

I’m not seeing anything specifically wrong here yet.

Please confirm that you do not have a second function named vote in your polls/views.py file.

Also identify what view you were looking at and what you did when this error was generated.

Finally, please post the traceback from the server console for this error.

I confirm only one function present for vote in views.py file. Got this error when trying to access http://127.0.0.1:8000/polls/

Below is error from console

WARNING: This is a development server. Do not use it in a production setting. Use a production WSGI or ASGI server instead.
For more information on production servers see: https://docs.djangoproject.com/en/5.2/howto/deployment/
Not Found: /
[23/Dec/2025 14:19:28] "GET / HTTP/1.1" 404 2306
Internal Server Error: /polls/
Traceback (most recent call last):
  File "C:\Users\snarayana\AppData\Local\Programs\Python\Python313\Lib\site-packages\django\core\handlers\exception.py", line 55, in inner
    response = get_response(request)
  File "C:\Users\snarayana\AppData\Local\Programs\Python\Python313\Lib\site-packages\django\core\handlers\base.py", line 197, in _get_response
    response = wrapped_callback(request, *callback_args, **callback_kwargs)
  File "C:\Python\practice\website\mysite\polls\views.py", line 18, in index
    return HttpResponse(template.render(context, request))
                        ~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^
  File "C:\Users\snarayana\AppData\Local\Programs\Python\Python313\Lib\site-packages\django\template\backends\django.py", line 107, in render
    return self.template.render(context)
           ~~~~~~~~~~~~~~~~~~~~^^^^^^^^^
  File "C:\Users\snarayana\AppData\Local\Programs\Python\Python313\Lib\site-packages\django\template\base.py", line 171, in render
    return self._render(context)
           ~~~~~~~~~~~~^^^^^^^^^
  File "C:\Users\snarayana\AppData\Local\Programs\Python\Python313\Lib\site-packages\django\template\base.py", line 163, in _render
    return self.nodelist.render(context)
           ~~~~~~~~~~~~~~~~~~~~^^^^^^^^^
  File "C:\Users\snarayana\AppData\Local\Programs\Python\Python313\Lib\site-packages\django\template\base.py", line 1016, in render
    return SafeString("".join([node.render_annotated(context) for node in self]))
                               ~~~~~~~~~~~~~~~~~~~~~^^^^^^^^^
  File "C:\Users\snarayana\AppData\Local\Programs\Python\Python313\Lib\site-packages\django\template\base.py", line 977, in render_annotated
    return self.render(context)
           ~~~~~~~~~~~^^^^^^^^^
  File "C:\Users\snarayana\AppData\Local\Programs\Python\Python313\Lib\site-packages\django\template\defaulttags.py", line 480, in render
    url = reverse(view_name, args=args, kwargs=kwargs, current_app=current_app)
  File "C:\Users\snarayana\AppData\Local\Programs\Python\Python313\Lib\site-packages\django\urls\base.py", line 98, in reverse
    resolved_url = resolver._reverse_with_prefix(view, prefix, *args, **kwargs)
  File "C:\Users\snarayana\AppData\Local\Programs\Python\Python313\Lib\site-packages\django\urls\resolvers.py", line 831, in _reverse_with_prefix
    raise NoReverseMatch(msg)
django.urls.exceptions.NoReverseMatch: Reverse for 'vote' with arguments '('',)' not found. 1 pattern(s) tried: ['polls/(?P<question_id>[0-9]+)/vote/\\Z']
[23/Dec/2025 14:19:37] "GET /polls/ HTTP/1.1" 500 111131

Not sure if it’s the cause, but your HTML form tag is formatted in curly braces: try replacing
{form action=“{% url ‘polls:vote’ question.id %}” method=“post”}
with
<form action=“{% url ‘polls:vote’ question.id %}” method=“post”> and see if it works.

it did not help.

WARNING: This is a development server. Do not use it in a production setting. Use a production WSGI or ASGI server instead.
For more information on production servers see: https://docs.djangoproject.com/en/5.2/howto/deployment/
Internal Server Error: /polls/
Traceback (most recent call last):
  File "C:\Users\snarayana\AppData\Local\Programs\Python\Python313\Lib\site-packages\django\core\handlers\exception.py", line 55, in inner
    response = get_response(request)
  File "C:\Users\snarayana\AppData\Local\Programs\Python\Python313\Lib\site-packages\django\core\handlers\base.py", line 197, in _get_response
    response = wrapped_callback(request, *callback_args, **callback_kwargs)
  File "C:\Python\practice\website\mysite\polls\views.py", line 18, in index
    return HttpResponse(template.render(context, request))
                        ~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^
  File "C:\Users\snarayana\AppData\Local\Programs\Python\Python313\Lib\site-packages\django\template\backends\django.py", line 107, in render
    return self.template.render(context)
           ~~~~~~~~~~~~~~~~~~~~^^^^^^^^^
  File "C:\Users\snarayana\AppData\Local\Programs\Python\Python313\Lib\site-packages\django\template\base.py", line 171, in render
    return self._render(context)
           ~~~~~~~~~~~~^^^^^^^^^
  File "C:\Users\snarayana\AppData\Local\Programs\Python\Python313\Lib\site-packages\django\template\base.py", line 163, in _render
    return self.nodelist.render(context)
           ~~~~~~~~~~~~~~~~~~~~^^^^^^^^^
  File "C:\Users\snarayana\AppData\Local\Programs\Python\Python313\Lib\site-packages\django\template\base.py", line 1016, in render
    return SafeString("".join([node.render_annotated(context) for node in self]))
                               ~~~~~~~~~~~~~~~~~~~~~^^^^^^^^^
  File "C:\Users\snarayana\AppData\Local\Programs\Python\Python313\Lib\site-packages\django\template\base.py", line 977, in render_annotated
    return self.render(context)
           ~~~~~~~~~~~^^^^^^^^^
  File "C:\Users\snarayana\AppData\Local\Programs\Python\Python313\Lib\site-packages\django\template\defaulttags.py", line 480, in render
    url = reverse(view_name, args=args, kwargs=kwargs, current_app=current_app)
  File "C:\Users\snarayana\AppData\Local\Programs\Python\Python313\Lib\site-packages\django\urls\base.py", line 98, in reverse
    resolved_url = resolver._reverse_with_prefix(view, prefix, *args, **kwargs)
  File "C:\Users\snarayana\AppData\Local\Programs\Python\Python313\Lib\site-packages\django\urls\resolvers.py", line 831, in _reverse_with_prefix
    raise NoReverseMatch(msg)
django.urls.exceptions.NoReverseMatch: Reverse for 'vote' with arguments '('',)' not found. 1 pattern(s) tried: ['polls/(?P<question_id>[0-9]+)/vote/\\Z']
[23/Dec/2025 14:50:42] "GET /polls/ HTTP/1.1" 500 111131

Can you share the index view, polls.views.index. Since the error is occuring when trying to access the /polls/ url, I suspect the source of the error is somewhere there

Yes, please post the index method along with the template that it is rendering.

This error is because you are passing a non-existent variable to {% url %}. If you install django-fastdev you can get a nice and understandable error message instead.

Index

def index(request):
    #return HttpResponse("Hello, world. You're at the polls index.")
    #latest_question_list = Question.objects.order_by("-pub_date")[:5]
    #output = ", ".join([q.question_text for q in latest_question_list])
    #return HttpResponse(output)

    # latest_question_list = Question.objects.order_by("-pub_date")[:5]
    # template = loader.get_template("polls/index.html")
    # context = {"latest_question_list":latest_question_list}
    # return HttpResponse(template.render(context, request))

    latest_question_list = Question.objects.order_by("-pub_date")[:5]
    context = {"latest_question_list": latest_question_list}
    return render(request, "polls/index.html", context)

Error

WARNING: This is a development server. Do not use it in a production setting. Use a production WSGI or ASGI server instead.
For more information on production servers see: https://docs.djangoproject.com/en/5.2/howto/deployment/
Internal Server Error: /polls/
Traceback (most recent call last):
  File "C:\Users\snarayana\AppData\Local\Programs\Python\Python313\Lib\site-packages\django\core\handlers\exception.py", line 55, in inner
    response = get_response(request)
  File "C:\Users\snarayana\AppData\Local\Programs\Python\Python313\Lib\site-packages\django\core\handlers\base.py", line 197, in _get_response
    response = wrapped_callback(request, *callback_args, **callback_kwargs)
  File "C:\Python\practice\website\mysite\polls\views.py", line 23, in index
    return render(request, "polls/index.html", context)
  File "C:\Users\snarayana\AppData\Local\Programs\Python\Python313\Lib\site-packages\django\shortcuts.py", line 25, in render
    content = loader.render_to_string(template_name, context, request, using=using)
  File "C:\Users\snarayana\AppData\Local\Programs\Python\Python313\Lib\site-packages\django\template\loader.py", line 62, in render_to_string
    return template.render(context, request)
           ~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^
  File "C:\Users\snarayana\AppData\Local\Programs\Python\Python313\Lib\site-packages\django\template\backends\django.py", line 107, in render
    return self.template.render(context)
           ~~~~~~~~~~~~~~~~~~~~^^^^^^^^^
  File "C:\Users\snarayana\AppData\Local\Programs\Python\Python313\Lib\site-packages\django\template\base.py", line 171, in render
    return self._render(context)
           ~~~~~~~~~~~~^^^^^^^^^
  File "C:\Users\snarayana\AppData\Local\Programs\Python\Python313\Lib\site-packages\django\template\base.py", line 163, in _render
    return self.nodelist.render(context)
           ~~~~~~~~~~~~~~~~~~~~^^^^^^^^^
  File "C:\Users\snarayana\AppData\Local\Programs\Python\Python313\Lib\site-packages\django\template\base.py", line 1016, in render
    return SafeString("".join([node.render_annotated(context) for node in self]))
                               ~~~~~~~~~~~~~~~~~~~~~^^^^^^^^^
  File "C:\Users\snarayana\AppData\Local\Programs\Python\Python313\Lib\site-packages\django\template\base.py", line 977, in render_annotated
    return self.render(context)
           ~~~~~~~~~~~^^^^^^^^^
  File "C:\Users\snarayana\AppData\Local\Programs\Python\Python313\Lib\site-packages\django\template\defaulttags.py", line 480, in render
    url = reverse(view_name, args=args, kwargs=kwargs, current_app=current_app)
  File "C:\Users\snarayana\AppData\Local\Programs\Python\Python313\Lib\site-packages\django\urls\base.py", line 98, in reverse
    resolved_url = resolver._reverse_with_prefix(view, prefix, *args, **kwargs)
  File "C:\Users\snarayana\AppData\Local\Programs\Python\Python313\Lib\site-packages\django\urls\resolvers.py", line 831, in _reverse_with_prefix
    raise NoReverseMatch(msg)
django.urls.exceptions.NoReverseMatch: Reverse for 'vote' with arguments '('',)' not found. 1 pattern(s) tried: ['polls/(?P<question_id>[0-9]+)/vote/\\Z']
[29/Dec/2025 10:02:45] "GET /polls/ HTTP/1.1" 500 120024

This view is rendering polls/index.html. We need to see that template.

index.html


{% if latest_question_list %}
    <ul>
        {% for question in latest_question_list %}
            <li><a href="/polls/{{question.id}}/"> {{ question.question_text}}</a></li>
        {% endfor %}
    </ul>
{% else %}
    <p> No polls are vailable.</p>
{% endif%}


tried with below as well.

<li><a href="{% url 'polls:detail' question.id %}">{{ question.question_text }}</a></li>

Is this the complete template? (I don’t see how this template can generate the error you’re reporting.)

Yes. thats complete template

let me delete polls app and try from beginning. i will report back if i am still running into same issue

Can you try this:

{% url 'polls:vote' question_id=question.id %}

Also, for debugging, you can add a line like:

<p>question: {{question}} id: {{question.id}}</p>