Django 2:项目根URL命名空间不起作用

时间:2018-01-04 09:19:19

标签: django url

项目根目录urls.py中有以下网址模式:

from django.contrib import admin
from django.urls import path, include


urlpatterns = [
    path('admin/', admin.site.urls),
    path('main/', include('main.urls', namespace='main')),
]

但是django抱怨以下信息:

django.core.exceptions.ImproperlyConfigured: Specifying a namespace in include() without providing an app_name is not supported. Set the app_name attribute in the included module, or pass a 2-tuple containing the list of patterns and app_name instead.

根据Django的documentation,'main'的模式应该是正确的。有什么问题?

1 个答案:

答案 0 :(得分:4)

您需要将app_name = 'main'添加到main.urls文件中。请参阅示例和说明here