title: Django tutorial: Reverse for 'detail' with arguments '('',)' not found. 1 pattern(s) tried: ['polls\\/(?P<question_id>[0-9]+)\\/$']
body: <p>I was following the Django tutorial when I got this problem.<br>
  I tried to copy paste and to read the tutorial again and again but I can't fix it.
  <br></p>
  
  <p>The error is: "Reverse for 'detail' not found. 'detail' is not a valid view function or pattern name."</p>
  
  <p>Error Traceback:</p>
  
  <pre><code>Environment:
  
  
  Request Method: GET
  Request URL: http://127.0.0.1:8000/polls/
  
  Django Version: 2.0.3
  Python Version: 3.5.2
  Installed Applications:
  ['polls',
   'django.contrib.admin',
   'django.contrib.auth',
   'django.contrib.contenttypes',
   'django.contrib.sessions',
   'django.contrib.messages',
   'django.contrib.staticfiles']
  Installed Middleware:
  ['django.middleware.security.SecurityMiddleware',
   'django.contrib.sessions.middleware.SessionMiddleware',
   'django.middleware.common.CommonMiddleware',
   'django.middleware.csrf.CsrfViewMiddleware',
   'django.contrib.auth.middleware.AuthenticationMiddleware',
   'django.contrib.messages.middleware.MessageMiddleware',
   'django.middleware.clickjacking.XFrameOptionsMiddleware']
  
  
  Template error:
  In template /home/cristian/Desktop/build/polls/templates/polls/index.html, error at line 1
     Reverse for 'detail' with arguments '('',)' not found. 1 pattern(s) tried: ['polls\\/(?P&lt;question_id&gt;[0-9]+)\\/$']
     1 : &lt;li&gt;&lt;a href=" {% url 'detail' question.id %} "&gt;{{ question.question_text }}&lt;/a&gt;&lt;/li&gt;
  
  Traceback:
  
  File "/home/cristian/.local/lib/python3.5/site-packages/django/core/handlers/exception.py" in inner
    35.             response = get_response(request)
  
  File "/home/cristian/.local/lib/python3.5/site-packages/django/core/handlers/base.py" in _get_response
    128.                 response = self.process_exception_by_middleware(e, request)
  
  File "/home/cristian/.local/lib/python3.5/site-packages/django/core/handlers/base.py" in _get_response
    126.                 response = wrapped_callback(request, *callback_args, **callback_kwargs)
  
  File "/home/cristian/Desktop/build/polls/views.py" in index
    10.     return render(request, 'polls/index.html', context)
  
  File "/home/cristian/.local/lib/python3.5/site-packages/django/shortcuts.py" in render
    36.     content = loader.render_to_string(template_name, context, request, using=using)
  
  File "/home/cristian/.local/lib/python3.5/site-packages/django/template/loader.py" in render_to_string
    62.     return template.render(context, request)
  
  File "/home/cristian/.local/lib/python3.5/site-packages/django/template/backends/django.py" in render
    61.             return self.template.render(context)
  
  File "/home/cristian/.local/lib/python3.5/site-packages/django/template/base.py" in render
    175.                     return self._render(context)
  
  File "/home/cristian/.local/lib/python3.5/site-packages/django/template/base.py" in _render
    167.         return self.nodelist.render(context)
  
  File "/home/cristian/.local/lib/python3.5/site-packages/django/template/base.py" in render
    943.                 bit = node.render_annotated(context)
  
  File "/home/cristian/.local/lib/python3.5/site-packages/django/template/base.py" in render_annotated
    910.             return self.render(context)
  
  File "/home/cristian/.local/lib/python3.5/site-packages/django/template/defaulttags.py" in render
    447.             url = reverse(view_name, args=args, kwargs=kwargs, current_app=current_app)
  
  File "/home/cristian/.local/lib/python3.5/site-packages/django/urls/base.py" in reverse
    88.     return iri_to_uri(resolver._reverse_with_prefix(view, prefix, *args, **kwargs))
  
  File "/home/cristian/.local/lib/python3.5/site-packages/django/urls/resolvers.py" in _reverse_with_prefix
    632.         raise NoReverseMatch(msg)
  
  Exception Type: NoReverseMatch at /polls/
  Exception Value: Reverse for 'detail' with arguments '('',)' not found. 1 pattern(s) tried: ['polls\\/(?P&lt;question_id&gt;[0-9]+)\\/$']
  </code></pre>
  
  <p><br>
  views.py:</p>
  
  <pre><code>from django.shortcuts import get_object_or_404, render
  from django.http import HttpResponseRedirect
  from django.urls import reverse
  from .models import Choice, Question
  
      def index(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)
  
      def detail(request, question_id):
          question = get_object_or_404(Question, pk=question_id)
          return render(request, 'polls/detail.html', {'question': question})
  
      def results(request, question_id):
          question = get_object_or_404(Question, pk=question_id)
          return render(request, 'polls/results.html', {'question': question})
  </code></pre>
  
  <p>models.py</p>
  
  <pre><code>import datetime
  
  from django.db import models
  from django.utils import timezone
  
  
  class Question(models.Model):
      question_text = models.CharField(max_length=200)
      pub_date = models.DateTimeField('date published', null=True)
      def __str__(self):
          return self.question_text
      def was_published_recently(self):
          return self.pub_date &gt;= timezone.now() - datetime.timedelta(days=1)
  
  
  class Choice(models.Model):
      question = models.ForeignKey(Question, on_delete=models.CASCADE)
      choice_text = models.CharField(max_length=200)
      votes = models.IntegerField(default=0)
      def __str__(self):
          return self.choice_text
  </code></pre>
  
  <p>urls.py</p>
  
  <pre><code>from django.urls import path
  
  from . import views
  
  urlpatterns = [
      path('', views.index, name='index'),
      path('&lt;int:question_id&gt;/', views.detail, name='detail'),
      path('&lt;int:question_id&gt;/results/', views.results, name='results'),
      path('&lt;int:question_id&gt;/vote/', views.vote, name='vote'),
  ]
  </code></pre>
  
  <p>index.html</p>
  
  <pre><code>&lt;li&gt;&lt;a href="{% url 'detail' question.id %}"&gt;{{ question.question_text }}&lt;/a&gt;&lt;/li&gt;
  </code></pre>
  
  <p>detail.html</p>
  
  <pre><code>&lt;h1&gt;{{ question.question_text }}&lt;/h1&gt;
  
  {% if error_message %}&lt;p&gt;&lt;strong&gt;{{ error_message }}&lt;/strong&gt;&lt;/p&gt;{% endif %}
  
  &lt;form action={% url 'polls:vote' poll.id %}" method="post"&gt;
  {% csrf_token %}
  {% for choice in question.choice_set.all %}
      &lt;input type="radio" name="choice" id="choice{{ forloop.counter }}" value="{{ choice.id }}" /&gt;
      &lt;label for="choice{{ forloop.counter }}"&gt;{{ choice.choice_text }}&lt;/label&gt;&lt;br /&gt;
  {% endfor %}
  &lt;input type="submit" value="Vote" /&gt;
  &lt;/form&gt;
  </code></pre>
  
  <p>I hope that you can help me, thanks.</p>