[英]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.