当前位置: 代码迷 >> 综合 >> Specifying a namespace in include() without providing an app_name
  详细解决方案

Specifying a namespace in include() without providing an app_name

热度:7   发布时间:2024-01-11 01:15:40.0

Django 执行 python manage.py runserver  报错,报错信息如下:

 File "/home/python/.virtualenvs/django_py3/lib/python3.5/site-packages/django/urls/conf.py", line 39, in include'Specifying a namespace in include() without providing an app_name ''Specifying a namespace in include() without providing an app_name '
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.


根据报错信息,查看conf.py文件   39行

不允许include 内定义一个命名空间却不提供app_name

查看自己的根路由文件

urlpatterns = [url(r'^admin/', admin.site.urls),url(r'^users/',include('users.urls',namespace='users'))]

从include()函数可以看出来,这个函数有两个参数,一个arg,一个namespace,我在代码中也是两个参数,但是异常中提示了,没有提供app_name,还提示需要传入一个两元元组,


可以看出来,arg就是那个元组,且给app_name赋值了,所以我们这里修改代码为:

urlpatterns = [url(r'^admin/', admin.site.urls),url(r'^users/',include(('users.urls',users),namespace='users'))]



  相关解决方案