简体   繁体   中英

urls.py in django

Here is the problem, the urls.py file in a django project look like this:

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

And I got an app installed, it is called 'testapp', so I wrote the include('testapp.urls') in the patterns.

The problem is that, Why should I put the testapp.urls in the quotation marks? Cuz I tried to put it like this: url('r^testapp/', include(testapp.urls)) , it didn't work. Why?

Your must import app in urls.py

import testapp

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

ad3w has answered your question. If you want to learn a little more about it check this out: http://www.djangobook.com/en/2.0/chapter08/

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM