While going through Django tutorial i commited an error because of which i am not able to execute python manage.py runserver. The exceptions and codes are mentioned below: In exception it is mentioned code error is in index.html line 4

27 views
Skip to first unread message

Avitab Ayan Sarmah

unread,
May 8, 2018, 12:34:01 PM5/8/18
to Django users
Exceptions:

PS C:\Users\AVITABAYAN\mysite> python manage.py runserver
Performing system checks...

System check identified no issues (0 silenced).
May 08, 2018 - 22:00:28
Django version 2.0.1, using settings 'mysite.settings'
Starting development server at http://127.0.0.1:8000/
Quit the server with CTRL-BREAK.
Internal Server Error: /
Traceback (most recent call last):
  File "c:\python36\lib\site-packages\django\core\handlers\exception.py", line 35, in inner
    response = get_response(request)
  File "c:\python36\lib\site-packages\django\core\handlers\base.py", line 158, in _get_response
    response = self.process_exception_by_middleware(e, request)
  File "c:\python36\lib\site-packages\django\core\handlers\base.py", line 156, in _get_response
    response = response.render()
  File "c:\python36\lib\site-packages\django\template\response.py", line 106, in render
    self.content = self.rendered_content
  File "c:\python36\lib\site-packages\django\template\response.py", line 83, in rendered_content
    content = template.render(context, self._request)
  File "c:\python36\lib\site-packages\django\template\backends\django.py", line 61, in render
    return self.template.render(context)
  File "c:\python36\lib\site-packages\django\template\base.py", line 175, in render
    return self._render(context)
  File "c:\python36\lib\site-packages\django\template\base.py", line 167, in _render
    return self.nodelist.render(context)
  File "c:\python36\lib\site-packages\django\template\base.py", line 943, in render
    bit = node.render_annotated(context)
  File "c:\python36\lib\site-packages\django\template\base.py", line 910, in render_annotated
    return self.render(context)
  File "c:\python36\lib\site-packages\django\template\defaulttags.py", line 314, in render
    return nodelist.render(context)
  File "c:\python36\lib\site-packages\django\template\base.py", line 943, in render
    bit = node.render_annotated(context)
  File "c:\python36\lib\site-packages\django\template\base.py", line 910, in render_annotated
    return self.render(context)
  File "c:\python36\lib\site-packages\django\template\defaulttags.py", line 211, in render
    nodelist.append(node.render_annotated(context))
  File "c:\python36\lib\site-packages\django\template\base.py", line 910, in render_annotated
    return self.render(context)
  File "c:\python36\lib\site-packages\django\template\defaulttags.py", line 447, in render
    url = reverse(view_name, args=args, kwargs=kwargs, current_app=current_app)
  File "c:\python36\lib\site-packages\django\urls\base.py", line 88, in reverse
    return iri_to_uri(resolver._reverse_with_prefix(view, prefix, *args, **kwargs))
  File "c:\python36\lib\site-packages\django\urls\resolvers.py", line 632, in _reverse_with_prefix
    raise NoReverseMatch(msg)
django.urls.exceptions.NoReverseMatch: Reverse for 'detail' with arguments '(1,)' not found. 1 pattern(s) tried: ['\\<int\\:pk\\/$']
[08/May/2018 22:00:42] "GET / HTTP/1.1" 500 134672

views.py:

from django.shortcuts import get_object_or_404, render
from django.http import HttpResponseRedirect
from django.urls import reverse
from django.views import generic

from . models import Choice, Question


class IndexView(generic.ListView):
template_name = 'polls/index.html'
context_object_name = 'latest_question_list'

def get_queryset(self):
"""Return the last five published questions."""
return Question.objects.order_by('-pub_date')[:5]


class DetailView(generic.DetailView):
model = Question
template_name = 'polls/detail.html'


class ResultsView(generic.DetailView):
model = Question
template_name = 'polls/results.html'


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 form.
return render(request, 'polls/detail.html', {
'question': question,
'error_message': "you didn't select a choice.",
})
else:
selected_choice.votes +=1
selected_choice.save()
#...
#...
#...
return HttpResponseRedirect(reverse('polls:results', args=(question.id,)))

index.html:

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


Julio Biason

unread,
May 8, 2018, 12:39:44 PM5/8/18
to django...@googlegroups.com
Your problem is your urls.py:


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

You are looking for a URL named "details" which accepts 1 number and Django does not know it.

--
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/1681bb6e-226e-4792-ab5c-1cadcf836eff%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.



--
Julio Biason, Sofware Engineer
AZION  |  Deliver. Accelerate. Protect.
Office: +55 51 3083 8101  |  Mobile: +55 51 99907 0554

Avitab Ayan Sarmah

unread,
May 8, 2018, 12:41:15 PM5/8/18
to django...@googlegroups.com
Wait I am sharing my URLs.py

To unsubscribe from this group and stop receiving emails from it, send an email to django-users...@googlegroups.com.



--
Julio Biason, Sofware Engineer
AZION  |  Deliver. Accelerate. Protect.
Office: +55 51 3083 8101  |  Mobile: +55 51 99907 0554

--
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/BgTiafZjozA/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.

Avitab Ayan Sarmah

unread,
May 8, 2018, 12:42:20 PM5/8/18
to Django users
polls/urls.py:

from django.urls import path

from . import views

app_name = 'polls'
urlpatterns = [
# ex: /polls/
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'),
]
To unsubscribe from this group and stop receiving emails from it, send an email to django-users...@googlegroups.com.

C. Kirby

unread,
May 8, 2018, 12:48:43 PM5/8/18
to Django users
You are missing a closing '>' in your detail url

Avitab Ayan Sarmah

unread,
May 8, 2018, 12:52:15 PM5/8/18
to django...@googlegroups.com
Please mention where exactly I missed >


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/BgTiafZjozA/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.

Avitab Ayan Sarmah

unread,
May 8, 2018, 12:54:11 PM5/8/18
to Django users
please mention where exactly i am missing >?

C. Kirby

unread,
May 8, 2018, 12:56:28 PM5/8/18
to Django users
Seriously?

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

You have posted several time in the last two days and every issue you have had has been a typo. People on this board are happy to help with django issues, but you should be really using an IDE that will catch at least some of these typos. PyCharm is a good one

Avitab Ayan Sarmah

unread,
May 8, 2018, 12:59:28 PM5/8/18
to django...@googlegroups.com
Thank you Kirby I found the error and now my code is running fine. Thanks again

Reply all
Reply to author
Forward
0 new messages