Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Django Admin. Change the title of app page

The default title for every app page is:

verbose_name + "administration"

How can I change it?

like image 922
behnam.m Avatar asked Dec 23 '25 02:12

behnam.m


1 Answers

Unfortunately, currently Django does not provide a clean way to override this header text, because it is hardcoded in the django.contrib.admin.sites.AdminSite.app_index method.

However, if you really need to do it, you can override this method and replace the default header with your text.

You will need to use your own custom AdminSite, if you're not using it yet. So, you'll need to change your urls.py to point to your custom class instead of default django admin urls, and also you'll need to register your models in your class, instead of default site.

class MyAdminSite(admin.AdminSite):

def app_index(self, request, app_label, extra_context=None):
    response: TemplateResponse = super().app_index(request, app_label, extra_context)
    response.context_data['title'] = 'Your header goes here;
    return response

Be sure to check the original method code, because it may differ in different Django versions. This code provided above is for Django 3.2.3.

like image 64
Pavel Shishmarev Avatar answered Dec 24 '25 17:12

Pavel Shishmarev



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!