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

Viewed 5507

I'm getting this error when running 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"),
]
2 Answers

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')) 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/).

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

simply change:

path('', include('main.urls'))
to
path('', include('main.urls', namespace='default'))

Related