Django 项目:命名空间“管理员"不是唯一的 [英] Django Project: namespace 'admin' isn't unique

查看:29
本文介绍了Django 项目:命名空间“管理员"不是唯一的的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在尝试运行 C:Python34/python manage.py makemigrations 时,我收到以下错误:(遵循 www.testandtrack.io)

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

错误

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

ma​​in/url.py

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

我已经粘贴了上面的各种 url.py 文件,并想象这是某个地方的问题.谁能指出我正确的方向,请解释一下?

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

路径('admin/', admin.site.urls),

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

除了 urls.py 文件(根)之外的所有文件......当我删除它时,我没有得到同样的错误,但我不知道这是否会导致其他问题,如果这是正确的做法?

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?

推荐答案

你是正确的,错误源于重复 path('admin/', admin.site.urls),你的 url.py 文件.正如其他人指出的那样,它通常只在根级别声明.

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.

这样想 - 您不希望每个应用程序都有一个单独的管理界面,而是希望能够从一个管理界面管理您的所有应用程序,这正是您拥有它时发生的事情仅在根 urls.py 文件中.

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.

这篇关于Django 项目:命名空间“管理员"不是唯一的的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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