[Django]跟着文档学Django-part4报错'polls' is not a registered namespace
来源:互联网 发布:飞机部件修理就业数据 编辑:程序博客网 时间:2024/04/30 06:22
官方文档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行):
10 {% if error_message %}<p><strong>{{ error_message }}</strong></p>{% endif %}11 12 <form action="{% url 'polls:vote' question.id %}" method="post">13 {% csrf_token %}
在找了很多方法之后,终于可以了。有两种方法。
(1)在polls.urls中修改(不推荐)
#polls.url 下添加一个app_name就好:from . import viewsapp_name = 'polls'urlpatterns = [...]
(2)在根urls中修改(比如官方文档就是mysite.urls)
加了个namespace
urlpatterns = [ #url(r'^polls/', include('polls.urls')), #更改成: url(r'^polls/', include('polls.urls', namespace='polls')), url(r'^admin/', admin.site.urls),
0 0
- [Django]跟着文档学Django-part4报错'polls' is not a registered namespace
- django报错: NoReverseMatch at / 'devops' is not a registered namespace
- NoReverseMatch at /polls/2/vote/ 'polls' is not a registered namespace
- raise NoReverseMatch("%s is not a registered namespace" % key)
- Django 报错 'AnonymousUser' object is not iterable 的解决办法
- Django出现报错'AnonymousUser' object is not iterable
- Django-part6-app's style-polls/static/polls/sytle.css
- 创建django项目报错:Django not found
- yum报错"This system is not registered with RHN"
- yum报错"This system is not registered with RHN"
- idea xml文件报错 URI is not registered 解决方法
- Django Tutorial Part4
- cxf 报错:prefix wsdp is not bound to a namespace
- Django笔记---项目报错之“xxx is not JSON serializable”
- 'my_templatetag' is not a registered tag library.
- django 报错:ValueError: The database backend does not accept 0 as a value for AutoField.
- django报错:AppRegistryNotReady
- django报错:ImproperlyConfigured
- [编程题]求小球落地5次后所经历的路程和第5次反弹的高度
- matplotlib为图片上添加触发事件进行交互
- 2017~新的生活
- (五)指针的初步认识
- Installing Ardublockly
- [Django]跟着文档学Django-part4报错'polls' is not a registered namespace
- Sagas模式
- 使用sax解析xml
- Building Ardublockly
- hexo+github博客环境搭建
- Angular指令渗透式理解
- C#-XML文件提取字符串+字符串存为XML文件+创建XML(自定义节点)文件+读取节点内容
- Running Uncompressed Ardublockly
- 数据存储与访问