Django Project: namespace 'admin' isn't unique
Asked Answered
L

5

17

on trying to run C:\Python34/python manage.py makemigrations, I get the following error: (following a tutorial from www.testandtrack.io)

Error

WARNINGS: ?: (urls.w005) URL namespace 'admin' isn't unique. You may not be able to reverse all URLS in this namespace

What precisely do I need to change and where do I need to look?

teachers/url.py

from django.contrib import admin
from django.urls import path
from django.urls import include, path
from . import views

urlpatterns = [
    path('admin/', admin.site.urls),
    path('', views.teachers, name='teachers'),
    
]

url.py

from django.contrib import admin
from django.urls import include, path
urlpatterns = [
    path('admin/', admin.site.urls),
    path('', include('main.urls')),
    path('teachers/', include('teachers.urls')),
]

main/url.py

urlpatterns = [
    path('admin/', admin.site.urls),
    path('header/', views.header, name='header'),
    path('', views.index, name='index'),
    
]

I've pasted the various url.py files above and imagine it's a problem somewhere there. could anyone please point me in the right direction, with an explanation please?

I've considered that I could/should remove

path('admin/', admin.site.urls),

from all but the urls.py file (root) .....when I do remove this, I don't get the same error, but I don't know if that will cause other problems and if this is the right thing to do?

Limonite answered 21/12, 2017 at 21:59 Comment(0)
L
8

You are correct in that the error stems from repeating path('admin/', admin.site.urls), in all of your url.py files. It is normally only declared at the root level as others have pointed out.

Think of it like this - You wouldn't want to have a separate admin interface for each app, rather you would want to be able to manage all of your apps from one admin interface which is exactly what occurs when you have it only in the root urls.py file.

Also, although the apps should be modular and independent they still need to be connected to a project to work.

Lignin answered 21/12, 2017 at 22:35 Comment(0)
B
23

You are declaring

path('admin/', admin.site.urls),

three times in your urls files. You just have to declare it once in the root urls.py of your project.

Bleeding answered 21/12, 2017 at 22:11 Comment(0)
L
8

You are correct in that the error stems from repeating path('admin/', admin.site.urls), in all of your url.py files. It is normally only declared at the root level as others have pointed out.

Think of it like this - You wouldn't want to have a separate admin interface for each app, rather you would want to be able to manage all of your apps from one admin interface which is exactly what occurs when you have it only in the root urls.py file.

Also, although the apps should be modular and independent they still need to be connected to a project to work.

Lignin answered 21/12, 2017 at 22:35 Comment(0)
H
2

Set your main/urls.py as

from django.urls import path
from django.views.generic import TemplateView

urlpatterns = [ 
    path(
        "header/", 
        TemplateView.as_view(template_name="header.html")),
]

And fix this inside the main URLs file teachers/urls.py as follows:

from django.contrib import admin
from django.urls import path, include
from django.conf import settings


urlpatterns = [
    path(
        'admin/', 
         admin.site.urls), 
    path('', 
         include('main.urls')),
] 
Haggi answered 7/1, 2022 at 8:42 Comment(0)
O
0

it's because of multiple declarations of that admin path. remove those extra line path('admin/', admin.site.urls) line from urls.py file except the project's url.py

Oisin answered 9/7, 2020 at 13:51 Comment(0)
T
0

There is a repetition of an admin path Search in the files urls. and delete duplicate path

Tyeshatyg answered 16/8, 2022 at 3:22 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.