在include()中使用名称空间时有关app_name的ImproperlyConfiguredError

发布于 2021-01-29 18:43:26

我目前正在尝试Django。我在urls.pynamespace中的一个参数中使用了参数。include()当我运行服务器并尝试浏览时,出现此错误。

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文件:

#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错误消息中所述的?

关注者
0
被浏览
41
1 个回答
  • 面试哥
    面试哥 2021-01-29
    为面试而生,有面试问题,就找面试哥。

    检查文档是否包含在此处

    您所做的不是传递参数包括的可接受方法。您可以这样做:

    url(r'^reviews/', include(('reviews.urls', 'reviews'), namespace='reviews')),
    


知识点
面圈网VIP题库

面圈网VIP题库全新上线,海量真题题库资源。 90大类考试,超10万份考试真题开放下载啦

去下载看看