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

Question:

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"),
]
Asked By: khadija ouakkaha

||

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.

Answered By: Ivan Starostin

simply change:

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

Answered By: MatthewJs
Categories: questions Tags: ,
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.