Django Project:名称空间"admin"不是唯一的 [英] Django Project: namespace 'admin' isn't unique

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

问题描述

在尝试运行C:\ Python34/python manage.py makemigrations时,出现以下错误:

on trying to run C:\Python34/python manage.py makemigrations, I get the following 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?

老师/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'),

]

我已经粘贴了上面的各种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

path('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?

推荐答案

您是正确的,因为错误是由于在所有url.py文件中重复path('admin/', admin.site.urls),而引起的.正如其他人指出的那样,通常只在根级别声明它.

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 Project:名称空间"admin"不是唯一的的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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