gpt4 book ai didi

Django 2 : project root url namespace not working

转载 作者:行者123 更新时间:2023-12-01 10:25:02 24 4
gpt4 key购买 nike

我在项目根目录的 urls.py 中有以下网址格式:

from django.contrib import admin
from django.urls import path, include


urlpatterns = [
path('admin/', admin.site.urls),
path('main/', include('main.urls', namespace='main')),
]

但是 django 提示以下消息:
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.

根据 Django 的 documentation , 'main' 的模式应该是正确的。有什么问题?

最佳答案

您需要添加 app_name = 'main'到 main.urls 文件。查看示例和说明 here .

关于 Django 2 : project root url namespace not working,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48092079/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com