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.
就是说,在项目的 urls 中 使用 include 时, 添加了namespace 参数,那么在相应的被包含模块中也要定义 对应的 app_name
修改后正确,代码如下
项目 urls
urlpatterns = [
path('admin/', admin.site.urls),
path('book/', include('bookinfo.urls', namespace='book')),
]
对应的模块urls中:
app_name = 'book'
urlpatterns = [
re_path(r'^index/$', views.index, name='index'),
]
原文:https://www.cnblogs.com/penn525/p/11152743.html