【发布时间】:2013-05-01 16:32:55
【问题描述】:
这是我的应用程序树:
myapp/
assets/
statics/
settings.py
urls.py
\\other stuff
main/
urls.py
views.py
templates/
base.html
index.html
\\other stuff
manage.py
在测试我的应用程序时,出现以下错误:
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.
这是base.html中涉及错误的代码:
{% load i18n %}
\\some stuff
<a class="brand" href="{% url 'index' %}">{{ site.name }}</a> <--- this line is the error
在main/urls.py我有:
urlpatterns = patterns('',
(r'^$', TemplateView.as_view(template_name="index.html")),
)
在myapp/urls.py我有:
urlpatterns = patterns('',
url(r'', include('main.urls'), name='index'),
)
谁能告诉我我做错了什么以及为什么名字'index'没有反向匹配?
【问题讨论】:
-
我真的不知道怎么做,我想把所有的主页逻辑放在“main”文件夹中,所有的应用程序配置放在“myapp”文件夹中。
-
我之前的评论很愚蠢,看看答案。