简体   繁体   English

Django中的urls.py

[英]urls.py in django

Here is the problem, the urls.py file in a django project look like this: 这是问题所在,django项目中的urls.py文件如下所示:

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. 我安装了一个名为“ testapp”的应用程序,因此我在模式中编写了include('testapp.urls')

The problem is that, Why should I put the testapp.urls in the quotation marks? 问题是,为什么我应该将testapp.urls放在引号中? Cuz I tried to put it like this: url('r^testapp/', include(testapp.urls)) , it didn't work. 因为我试图这样说: url('r^testapp/', include(testapp.urls)) ,它没有用。 Why? 为什么?

Your must import app in urls.py 您必须在urls.py中导入应用

import testapp

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

ad3w has answered your question. ad3w回答了您的问题。 If you want to learn a little more about it check this out: http://www.djangobook.com/en/2.0/chapter08/ 如果您想了解更多有关它的信息,请查看: http : //www.djangobook.com/en/2.0/chapter08/

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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