官方文档tutorial04 https://docs.djangoproject.com/en/1.10/intro/tutorial04/,会在运行中出现如下错误:
NoReverseMatch at /polls/3/
‘polls’ is not a registered namespace
Request Method: GET
Request URL: http://127.0.0.1:8000/polls/3/
Django Version: 1.9.6
Exception Type: NoReverseMatch
Exception Value:
‘polls’ is not a registered namespace
代码报错会出现(第12行):
- 1
- 2
- 3
- 4
在找了很多方法之后,终于可以了。有两种方法。
(1)在polls.urls中修改(不推荐)
- 1
- 2
- 3
- 4
(2)在根urls中修改(比如官方文档就是mysite.urls)
加了个namespace
原文地址:http://blog.csdn.net/mwmoo/article/details/53783140