运行环境
PyCharm 2017.1
Django 2.0.1
python 3.6.1
错误代码如下:
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.
意思为:
在include方法里面指定namespace却不提供app_name是不允许的。
在包含的模块里设置app_name变量,或者在include方法里面提供app_name参数。
解决方法:
方法1:在项目的urls.py中修改
from django.urls import path,include
from app import urls as app_url
urlpatterns = [
path('', include((common_url,'common'), namespace='common')), #此处include后的第一个参数用元祖传两个值,第二个值为app_name
]
方法2:在app/urls.py中修改
from django.urls import path
from .views import index
app_name='common' #此处增加app_name变量
urlpatterns = [
path('',index,name='index'),
]