urls.py中的空网址 [英] Empty url in urls.py

查看:55
本文介绍了urls.py中的空网址的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个有多个视图的项目,例如-索引,联系人和有关。
我想要 url www.aaa.net 链接到索引视图, www.aaa.net/about 关于视图等等,例如
在项目urls.py中,我写了

I have a project with several views e.g. - index, contacts and about. And I want url www.aaa.net links to index view, www.aaa.net/about to about view and so on In project urls.py I wrote

url(r'^$', include('mysite.urls'))

在我写的应用urls.py中

In app urls.py I wrote

url(r'^$',views.index,name='index'),
url(r'about/$',views.about,name='about'),
url(r'contacts/$',views.contacts,name='contacts'),

但是它仅适用于索引视图,关于和联系人根本不起作用

But it works only with index view, about and contacts didn't work at all

推荐答案

url(r'^$', include('mysite.urls'))

试图在正则表达式匹配中包含 $ 意味着url模式的结尾,这就是问题的原因。

When you are trying to include, $, in the regex match implies the end of the url pattern, which was the cause of the issue.

您可能正在寻找

url(r'^', include('mysite.urls'))

有关包括网址格式的更多信息此处

More info on including URL patterns here

这篇关于urls.py中的空网址的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆