MENU

Django:Specifying a namespace in include() without providing an app_name is not supported.

概述

配置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 in
cluded module, or pass a 2-tuple containing the list of patterns and app_name instead.`

源代码分析

urlpatterns = [
    ...
    path('subapp/', include("subApp.urls", namespace="app"))
    ...
]

问题分析

字面意思,include传入的参数不能只有命名空间,还要有应用程序名称。这两个东西放在一个元组中传入即可

解决方法

修改代码为

path('subapp/', include(("subApp.urls", "app"), namespace="app"))

include传入的参数1是一个元组,元组的第二个元素与后面的namespace同名就即可


文章标题:Django:Specifying a namespace in include() without providing an app_name is not supported.
如果文中内容侵犯了您的权益,请及时与博主取得联系进行删除!
本站文章未经许可禁止转载,本文地址:https://blog.wanvale.com/archives/334/

Archives QR Code Tip
QR Code for this page
Tipping QR Code