3

I have seen a few other questions about this on SO but they didn't solve my problem. I am running Django 1.8.5, Python 2.7.6.

I updated the root urls.py to

from django.conf.urls import include, url
from django.contrib import admin

urlpatterns = [
    url(r'^polls/', include('polls.urls', namespace="polls")),
    url(r'^admin/', include(admin.site.urls)),
]

and polls/templates/polls/index.html to

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

I get the error

NoReverseMatch at /polls/
u'polls' is not a registered namespace. 

I have tried restarting the development server as the other answers I have suggested, as well as including {% load url from future %} in the template code; neither has worked. Not sure what I am missing, my code matches the files in the tutorial.

Edit: polls/urls.py

from django.conf.urls import url
from . import views

urlpatterns = [
    url(r'^$', views.index, name='index'),
    url(r'^(?P<question_id>[0-9]+)/$', views.detail, name='detail'), 
    url(r'^(?P<question_id>[0-9]+)/results/$', views.results, name='results'),
    url(r'^(?P<question_id>[0-9]+)/vote/$', views.vote, name='vote'),] 
Andrew
  • 6,295
  • 11
  • 56
  • 95
  • 2
    Show the polls.urls code – Paulo Pessoa Oct 15 '15 at 14:58
  • 2
    What's the location of the root `urls.py` (occasionally new users create a second urls.py in the wrong place). – Alasdair Oct 15 '15 at 15:18
  • root urls.py is in mysite/urls.py, where mysite is the name of the root directory (not the nested mysite directory). So if I have this in a "development" directory with my other repos it is in Development/mysite/urls.py – Andrew Oct 15 '15 at 15:29

1 Answers1

2

If the ROOT_URLCONF setting is mysite.urls, then the urls.py should be in the nested mysite directory, i.e. mysite/mysite/urls.py.

Alasdair
  • 298,606
  • 55
  • 578
  • 516