这是问题,django项目中的urls.py文件如下所示:
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))
,它没有用。
为什么呢?
答案 0 :(得分:4)
您必须在urls.py中导入应用
import testapp
urlpatterns = patterns('',
...
url(r'^admin/', include(admin.site.urls)),
url(r'^testapp/', include(testapp.urls)),
)
答案 1 :(得分:1)
ad3w已回答你的问题。如果您想了解更多信息,请查看:http://www.djangobook.com/en/2.0/chapter08/