Hansong Li Hansong Li - 3 months ago 15
Python Question

django: instantiating AdminSite changes not reflected

I am trying to change the templates of admin site, and tried overriding by creating a local template for admin, but failed without knowing why: template way. So now I tried to create a instance of AdminSite and make changes from there, but still failed. I have:

urls.py
urlpatterns = [
url(r'^myadmin/', admin.site.urls),

admin.py
from django.contrib import admin
from .models import Equipment, Calibration, Flag, Tests
from django.contrib.admin import AdminSite

class MyAdminSite(AdminSite):
site_header = "Equipment Calibration Database"
site_title = "Equipment Calibration Database"
index_title = "Equipment Calibration Database"
# Register your models here.
admin_site = MyAdminSite(name = 'myadmin')

admin.site.register(Equipment)
admin.site.register(Calibration)
admin.site.register(Flag)
admin.site.register(Tests)


Now when I go to http://127.0.0.1:8000/myadmin/, I still find that none of the text I specified in MyAdminSite is in effect, I still see "Django administration" and "Site administration".

This is all acting really weird and helps are greatly welcome

Answer

To change the text in the admin, all you need to add to the admin.py is as follows:

admin.site.site_header = "Equipment Calibration Database"
admin.site.site_title = "Equipment Calibration Database"
admin.site.index_title = "Equipment Calibration Database"
Comments