django - 将urls.py分成多个

时间:2014-09-25 20:33:44

标签: python django

我知道,这实际上是django BUT的基础知识

我试图将我的巨大urls.py分成3块。所有3个urls_xxx.py都位于一个文件夹下:mysite

然后在主urls.py中我做了:

#urls.py
urlpatterns += patterns('',

    url(r'^', include('urls_search')),
    url(r'^', include('urls_ajax')),
    url(r'^', include('urls_sitemaps')),

)

但是它说:

ImportError at /
No module named urls_search

这是urls_search.py​​:

urlpatterns = patterns('myapp.views',
    url(r'^advancedsearch/$', 'advsearch', name="advsearch"),
    url(r'^advancedsearch/tc/$', 'advtcsearch', name="advtcsearch"),
)

我的URLCONF:

ROOT_URLCONF = 'mysite.urls'
我做错了什么?我正在使用Django 1.4

3 个答案:

答案 0 :(得分:4)

删除.py,如下所示:

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

答案 1 :(得分:3)

您可以在主要' urls.py':

中执行此操作
from mysites.url_1 import urlpatterns as url1
from mysites.url_2 import urlpatterns as url2
from mysites.url_3 import urlpatterns as url3

urlpatterns = url1
urlpatterns += url2
urlpatterns += url3

答案 2 :(得分:-1)

主要url.py

from mysites import url1
from mysites import url2
from mysites import url3

urlpatterns = url1.urlpatterns
urlpatterns += url2.urlpatterns
urlpatterns += url3.urlpatterns

等等