在include()中使用名称空间时有关app_name的ImproperlyConfiguredError [英] ImproperlyConfiguredError about app_name when using namespace in include()
本文介绍了在include()中使用名称空间时有关app_name的ImproperlyConfiguredError的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我目前正在尝试Django。我在urls.py中的 include()
之一中使用了命名空间
参数。当我运行服务器并尝试浏览时,
出现此错误。
I am currently trying out Django. I use the namespace
argument in one of my include()
s in urls.py. When I run the server and try to browse,
I get this error.
File "C:\Users\User\AppData\Local\Programs\Python\Python36-32\lib\site-packages\django\urls\conf.py", line 39, in include
'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.
这些是我的urls.py文件:
These are my urls.py files:
#project/urls.py
from django.conf.urls import include, url
from django.contrib import admin
urlpatterns = [
url(r'^reviews/', include('reviews.urls', namespace='reviews')),
url(r'^admin/', include(admin.site.urls)),
]
和
#app/urls.py
from django.conf.urls import url
from . import views
urlpatterns = [
# ex: /
url(r'^$', views.review_list, name='review_list'),
# ex: /review/5/
url(r'^review/(?P<review_id>[0-9]+)/$', views.review_detail, name='review_detail'),
# ex: /wine/
url(r'^wine$', views.wine_list, name='wine_list'),
# ex: /wine/5/
url(r'^wine/(?P<wine_id>[0-9]+)/$', views.wine_detail, name='wine_detail'),
]
我如何通过错误消息中所述的 app_name
?
What do I pass the app_name
as stated in the error message?
推荐答案
在此处。
您所做的不是传递参数以包含的可接受方法。您可以这样做:
What you've done is not an acceptable way of passing parameters to include. You could do:
url(r'^reviews/', include(('reviews.urls', 'reviews'), namespace='reviews')),
这篇关于在include()中使用名称空间时有关app_name的ImproperlyConfiguredError的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文