我已经在SO上看到了其他一些问题,但他们并没有解决我的问题。我正在运行Django 1.8.5,Python 2.7.6。
我将根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/', include(admin.site.urls)),
]
和polls / templates / polls / 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 %}
我收到错误
NoReverseMatch at /polls/
u'polls' is not a registered namespace.
我已尝试按照我建议的其他答案重新启动开发服务器,并在模板代码中包含{%load url from future%};两者都没有奏效。不确定我缺少什么,我的代码与教程中的文件匹配。
编辑: 轮询/ 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'),]
答案 0 :(得分:2)
如果ROOT_URLCONF
设置为mysite.urls
,则urls.py应位于嵌套mysite
目录中,即mysite/mysite/urls.py
。