I study Django on documentation, I reached the test. With

>>> from django.core.urlresolvers import reverse >>> response = client.get(reverse('polls:index')) 

throws an error KeyError: 'polls' NoReverseMatch: 'polls' is not a registered namespace Here is my urls.py

 from django.conf.urls import include, url from django.contrib import admin urlpatterns = [ url(r'^polls/', include('polls.urls', namespace = 'polls')), url(r'^admin/', admin.site.urls), ] 

/polls/urls.py

 from django.conf.urls import url from . import views urlpatterns = [ url(r'^$', views.IndexView.as_view(), name='index'), url(r'^(?P<pk>[0-9]+)/$', views.DetailView.as_view(), name='detail'), url(r'^(?P<pk>[0-9]+)/results/$', views.ResultsView.as_view(), name='results'), url(r'^(?P<question_id>[0-9]+)/vote/$', views.vote, name='vote'), ] 

views.py (left only IndexView class):

 from django.shortcuts import get_object_or_404, render from django.http import HttpResponseRedirect from django.core.urlresolvers 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] 

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

    1 answer 1

    Add the following line to the urls.py file in the application:

     from django.conf.urls import include, url from django.contrib import admin app_name="pools" #указывает пространство имен urlpatterns = [ url(r'^polls/', include('polls.urls', namespace = 'polls')), url(r'^admin/', admin.site.urls), ] 

    Details are here: https://docs.djangoproject.com/en/2.0/intro/tutorial03/

    • Alas, it does not help. app_name = "polls" I used to have in polls / urls.py, but then deleted it - pythonbek
    • And what is the version of Django? Was the variable in this file /polls/urls.py? - user268178
    • 1.11.7. Yes, in polls / urls.py. Then, too, did not work - pythonbek
    • And that's all, thanks for the help). I restarted the program - it worked - pythonbek