Empty url in urls.py

若如初见. 提交于 2019-12-24 02:56:10

问题


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'))

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


回答1:


Remove the $ at the end of

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

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

You are probably looking for

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

More info on including URL patterns here



来源:https://stackoverflow.com/questions/17601751/empty-url-in-urls-py

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!