您好我是django的初学者,我离开部署该网站是一个愚蠢的网址问题。我有一个简单的网站,有5页home,contact,about,reasons, and benefits
。简单的权利,url conf将为(r'^home/$',index)
,其余页面如下所示。当我转到主页/home/
时,问题就出现了。现在转到导航上的任何其他页面,例如/reasons/
或/about/
,它们就不会被调用,而是被称为/home/reasons/
或/home/about/
。更重要的是,如果从/home/about/
我点击返回主页,则呼叫为/home/about/home
。如你所见,这种情况永远存在。如何对页面的每个请求都是简单的/about/
或/contact/
而不是/home/contact or /home/about
。
我定义了一个/home/contact/home/home/about/reasons/home
我可能把所有这些都放在urlconf中
注意:这都是在django dev服务器上运行的
答案 0 :(得分:2)
确保您的模板中使用的是绝对网址,而不是
<a href="contacts">Contacts</a>
应该是
<a href="/contacts/">Contacts</a>
并且模板中有否 base tag
答案 1 :(得分:2)
如果您的网址如下所示:
(r'^home/$', myapp.views.index)
然后在模板中使用它:
<a href="{% url myapp.views.index %}>some text</a>
避免错误的解释。 Django将完成剩下的工作。
对于Django 1.5使用
<a href="{% url 'myapp.views.index' %}>some text</a>
答案 2 :(得分:1)
确保您网页上的链接看起来像
<a href="/home/">...</a> <-- this will take you to home page
而不是
<a href="home/">...</a> <-- this will take you to {current_url}/home/