?:(urls.W005)URL名称空间"main"不是唯一的.您可能无法撤消此命名空间中的所有URL [英] ?: (urls.W005) URL namespace 'main' isn't unique. You may not be able to reverse all URLs in this namespace

查看:52
本文介绍了?:(urls.W005)URL名称空间"main"不是唯一的.您可能无法撤消此命名空间中的所有URL的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

运行 python manage.py runserver

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

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

mysite/urls.py

django.contrib导入管理员中的

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

django.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('', include('main.urls')) means that all of the url patterns from main will be included without any additional prefix.

path('asdf/',include('main.urls'))意味着来自 main 的所有url模式都将包含其他 asdf/前缀,因此根索引网址将变为 asdf/,而 about/将变为 asdf/about/(在您的情况- about/about/).

path('asdf/', include('main.urls')) would mean that all of the url patterns from main will be included with additional asdf/ prefix, so root index url would become asdf/ and about/ would become asdf/about/ (in your case - about/about/).

如果您在main.urls中拥有100500个网址格式,则仍只需包含一次即可.

If you'd have 100500 url patterns in main.urls you'd still need to include them only once.

这篇关于?:(urls.W005)URL名称空间"main"不是唯一的.您可能无法撤消此命名空间中的所有URL的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆