简体   繁体   中英

Django admin unregister Sites

I've been trying to unregister the admin for sites in django by doing the following:

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).

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. 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.

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 ). In your example above you were unregistering Site before Django had the chance to register is it.

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 ;-)

My INSTALLED_APPS usually start with the django.contrib apps, then any 3rd-party applications, then my apps at the bottom. I only change this if I have a very good reason to.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM