khadija ouakkaha
khadija ouakkaha

Reputation: 59

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

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"),
]

Upvotes: 4

Views: 8432

Answers (2)

MatthewJs
MatthewJs

Reputation: 1

simply change:

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

Upvotes: 0

IVNSTN
IVNSTN

Reputation: 9299

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.

Upvotes: 6

Related Questions