【发布时间】:2015-06-08 22:37:03
【问题描述】:
我有一个 Django 项目,我想为所有网站的网页使用一个应用程序。我的项目如下所示:
project
src
project
urls.py
views.py
...
web
migrations #package
urls.py
views.py
...
templates
web
index.html # I want this to be my root page
page2.html # This is the second page I'm trying to link to
我正在尝试在index.html 中创建一个链接,它将带我到page2.html。这就是我正在做的事情
在project->urls.py 我有url(r'^$', include('web.urls', namespace="web")),。这应该将所有页面请求指向 url http://127.0.0.1:8000/ 到页面 index.html
project->views.py 为空,因为我希望 web 应用提供所有网页。
在web->urls.py 我有url(r'^$', views.index, name='home_page'),它与web->views.py 和函数有关
def index(request):
print("Main index Page")
return render(request, 'web/index.html', {})
返回正确的页面。
在我为page2.html 添加指向index.html 的链接之前,这一切正常。链接如下所示:{% url 'web:page2' %}。我更新web->urls.py。我将以下函数添加到web->views.py:
def page2(request):
print("Page2")
return render(request, 'web/page2.html', {})
现在我明白了
Reverse for 'page2' with arguments '()' and keyword arguments '{}' not found. 1 pattern(s) tried: ['$page2/?$']
突出显示 '{% url 'web:page2' %}' 行。
当我删除链接时,一切正常。我的逻辑/设置有什么问题?
【问题讨论】:
标签: django django-views