How to change dynamically "Site administration" string in Django's admin?
admin, django
Solution
The `index()` view is inside `django.contrib.admin.site.AdminSite` class and supports `extra_context` as well, you could override it, something like:
def index(self, *args, **kwargs):
return admin.site.__class__.index(self, extra_context={'title':'customized title'}, *args, **kwargs)
admin.site.index = index.__get__(admin.site, admin.site.__class__)
Also you could override `AdminSite` directly and use `customized_site` instead of `admin.site`:
class CustomizedAdminSite(AdminSite):
def index(self, *args, **kwargs):
return super(CustomizedAdminSite, self).index(extra_context={...}, *args, **kwargs)
customized_site = CustomizedAdminSite()
If you want to have `title` in all Admin pages, better to use context processor or customize some template tag if you can.
Problem
I want to replace dynamically "Site administration" by a custom string in my admin. I've already overridden "base.html" for some other purpose, but now I need to pass a variable to this template to replace `{{ title }}` in ``` {% block content_title %}{% if title %}<h1>{{ title }}</h1>{% endif %}{% endblock %} ``` I've seen from this question that a variable can be passed to the change list template by overriding `changelist_view` and adding an `extra_context` in the model admin, but how can I pass an extra context to the "main" page of the admin"?