[英]Django url reverse matching error
This is my application tree : 这是我的应用程序树:
myapp/
assets/
statics/
settings.py
urls.py
\\other stuff
main/
urls.py
views.py
templates/
base.html
index.html
\\other stuff
manage.py
When testing my application, I have the following error : 测试我的应用程序时,出现以下错误:
Error during template rendering
In template /app/main/templates/base.html, error at line 32
Reverse for 'index' with arguments '()' and keyword arguments '{}' not found.
Here is the code in base.html
involved in the error : 这是涉及错误的
base.html
中的代码:
{% load i18n %}
\\some stuff
<a class="brand" href="{% url 'index' %}">{{ site.name }}</a> <--- this line is the error
in main/urls.py
I have : 在
main/urls.py
我有:
urlpatterns = patterns('',
(r'^$', TemplateView.as_view(template_name="index.html")),
)
in myapp/urls.py
I have : 在
myapp/urls.py
我有:
urlpatterns = patterns('',
url(r'', include('main.urls'), name='index'),
)
Can someone please tell my what I am doing wrong and why the name 'index'
is not reverse matched? 有人可以告诉我我做错了什么,为什么名称
'index'
没有反向匹配?
name
is for single views, it doesn't go with the include statement. name
是针对单个视图的,它不与include语句一起使用。 Try this way: 尝试这种方式:
in main/urls.py: 在main / urls.py中:
urlpatterns = patterns('',
url(r'^$', TemplateView.as_view(template_name="index.html"),
name='index'),
)
in myapp/urls.py: 在myapp / urls.py中:
urlpatterns = patterns('',
url(r'', include('main.urls')),
)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.