2011-12-26 77 views
1

這裏的問題是,在一個Django項目看起來像這樣的urls.py文件:urls.py在Django

urlpatterns = patterns('', 
    ... 
    url(r'^admin/', include(admin.site.urls)), 
    url(r'^testapp/', include('testapp.urls')), #Here is the problem. 
) 

而且我安裝了一個應用程序,它被稱爲「testapp」,所以我寫了模式中的include('testapp.urls')

問題是,爲什麼我要把testapp.urls放在引號中? 因爲我試圖把它這樣寫:url('r^testapp/', include(testapp.urls)),它沒有工作。 爲什麼?

回答

4

你必須在urls.py導入應用

import testapp 

urlpatterns = patterns('', 
    ... 
    url(r'^admin/', include(admin.site.urls)), 
    url(r'^testapp/', include(testapp.urls)), 
)