gpt4 book ai didi

python - ? : (urls. W005) URL 命名空间 'main' 不是唯一的。您可能无法反转此命名空间中的所有 URL

转载 作者:行者123 更新时间:2023-11-30 21:55:25 25 4
gpt4 key购买 nike

我在运行 python manage.py runserver 时收到此错误

?: (urls.W005) URL namespace 'main' isn't unique. You may not be able to reverse all URLs in this namespace

mysite/urls.py

from django.contrib import admin
from django.urls import path, include
from users import views as user_views

urlpatterns = [
path('register/', user_views.register, name='register'),
path('', include('main.urls')),
path('admin/', admin.site.urls),
path('about/', include('main.urls')),
]

main/urls.py

from django.urls import path
from . import views

app_name = 'main'

urlpatterns = [
path('', views.blog, name='blog'),
path("about/", views.about, name="about"),
]

最佳答案

path('', include('main.urls'))表示 main 中的所有 url 模式将被包含在内,没有任何附加前缀。

path('asdf/', include('main.urls'))意味着 main 中的所有 url 模式将包含在附加 asdf/ 中前缀,因此根索引 url 将变为 asdf/about/将变成asdf/about/ (在您的情况下 - about/about/ )。

如果 main.urls 中有 100500 个 url 模式,您仍然只需将它们包含一次。

关于python - ? : (urls. W005) URL 命名空间 'main' 不是唯一的。您可能无法反转此命名空间中的所有 URL,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56807808/

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