简体   繁体   English

Django管理员取消注册网站

[英]Django admin unregister Sites

I've been trying to unregister the admin for sites in django by doing the following: 我一直在尝试通过执行以下操作取消注册django中的网站管理员:

from django.contrib.sites.models import Site

admin.site.unregister(Site)

However this gives me an error stating that "Site" is not registered (even though it showed up in admin before). 然而,这给了我一个错误,指出“Site”没有注册(即使它之前出现在管理员中)。

If I try doing the following I get no errors but "Site" stays in the admin: 如果我尝试执行以下操作,则不会出现任何错误,但“网站”会保留在管理员中:

from django.contrib.sites.models import Site

admin.site.register(Site)
admin.site.unregister(Site)

I need the sites app and cannot take it out of INSTALLED_APPS in settings. 我需要网站应用程序,并且无法在设置中将其从INSTALLED_APPS中删除。 However the admin for it is utterly useless to me. 但管理员对我来说完全没用。 Any ideas on what I am doing wrong here? 我在这里做错了什么想法?

Thanks! 谢谢!

The order of your INSTALLED_APPS setting is important. INSTALLED_APPS设置的顺序很重要。

When Django starts it will import the applications in INSTALLED_APPS in the order they are defined ( https://docs.djangoproject.com/en/1.11/ref/applications/#how-applications-are-loaded ). 当Django启动时,它将按照定义的顺序导入INSTALLED_APPS中的应用程序( https://docs.djangoproject.com/en/1.11/ref/applications/#how-applications-are-loaded )。 In your example above you were unregistering Site before Django had the chance to register is it. 在上面的示例中,您在Django有机会注册之前取消注册Site

There isn't much you can do in terms of troubleshooting except for reading the logs very carefully. 除了非常仔细地阅读日志之外,在故障排除方面您无能为力。 After staring at them for a while you either become one with Django and understand it all, or you come here like the rest of us ;-) 在盯着他们看了一会儿之后,你要么成为Django的一员并且理解这一切,要么就像我们其他人一样来到这里;-)

My INSTALLED_APPS usually start with the django.contrib apps, then any 3rd-party applications, then my apps at the bottom. 我的INSTALLED_APPS通常从django.contrib应用程序开始,然后是任何第三方应用程序,然后是底部的应用程序。 I only change this if I have a very good reason to. 如果我有一个很好的理由,我只改变这一点。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 在django admin中有条件地注销或注册模型 - unregister or register models conditionally in django admin Django:具有多种网站和语言的管理员 - Django: Admin with multiple sites & languages 在Django管理员中使用Django站点框架 - Using the Django sites framework in the Django admin django 站点并在管理编辑器中显示 id - django sites and showing id in admin editor 为什么“django.contrib.admin.sites”没有“注册”属性? - Why 'django.contrib.admin.sites' has no attribute 'register'? Django-Admin 站点的内置树视图? - Built-in tree view for Django-Admin sites? Django:如何在使用 django-allauth 时从 Django 管理员隐藏站点框架? - Django: How to hide Sites framework from Django Admin while using django-allauth? Django自定义admin.site.register + admin.site.unregister在第一个HTTP GET(Apache + mod WSGI)上发生冲突的AlreadyRegistered + NotRegistered - Django custom admin admin.site.register + admin.site.unregister conflicting AlreadyRegistered + NotRegistered on 1st HTTP GET (Apache + mod WSGI) 导入django.contrib.sites时无法访问Django管理站点 - Can't access Django admin site while import django.contrib.sites 一个Apache上的多个Django管理站点...当我登录一个时,我会从另一个登录 - Multiple Django Admin Sites on one Apache… When I log into one I get logged out of the other
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM