如何解決Django2.0項目urls命名空間報錯

報錯信息:

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.

報錯中已說明解決辦法,設置app_name屬性,或者傳遞一個兩個元素的元祖,包含路由匹配列表和app_nameweb

解決辦法:

1 在app.urls中聲明app_name,與namespace對應

app_name='app'
urlpatterns = [
    url(r'^index/',views.index),
]

2 include方法中傳入元祖

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