从 Django-admin 中删除默认应用程序

2022-01-25 00:00:00 python django django-admin

问题描述

默认情况下,在 Django-admin 中有用户、组和站点应用程序.如何删除组和网站?

By default, in Django-admin there is Users, Groups, and Sites apps. How can I remove Groups and Sites?

我试图从根 url 中删除 admin.autodiscover().然后,当我在我的应用模型中的某处添加类似 admin.site.register(User, UserAdmin) 的东西时,我得到了一个 AlreadyRegistered 异常(这是相当正确的 - 模型用户已经在 django.contrib.auth 中注册).

I tried to remove admin.autodiscover() from root urls. Then, when I added something like admin.site.register(User, UserAdmin) somewhere in my app models I got an AlreadyRegistered exception (this is fairly right - models users already registered in django.contrib.auth).


解决方案

在你知道肯定会加载的 admin.py 中,试试:

In an admin.py you know will definitely be loaded, try:

admin.site.unregister(User)
admin.site.unregister(Group)
admin.site.unregister(Site)

相关文章