How to change title for the tab of User Change Page of Django admin?

Question:

I’m working on Django and wanted to change the default title for the tab of User Change Page of Django admin as marked in the pic :

enter image description here

my admin.py file is:

from django.contrib import admin
from django.contrib.auth.admin import UserAdmin


from .models import CustomUser


class CustomUserAdmin(UserAdmin):

    change_list_template='change_list_form.html'

    change_form_template = 'change_form.html'

    add_form_template='add_form.html'

    list_display = ('first_name','last_name','email','is_staff', 'is_active',)
    list_filter = ('first_name','email', 'is_staff', 'is_active',)

    search_fields = ('email','first_name','last_name','a1','a2','city','state','pincode')
    ordering = ('first_name',)

    add_fieldsets = (
        ('Personal Information', {
            # To create a section with name 'Personal Information' with mentioned fields
            'description': "",
            'classes': ('wide',),  # To make char fields and text fields of a specific size
            'fields': (('first_name','last_name'),'email','a1','a2','city','state','pincode','check',
                       'password1', 'password2',)}
        ),
        ('Permissions',{
            'description': "",
            'classes': ('wide', 'collapse'),
            'fields':( 'is_staff', 'is_active','date_joined')}),
    )

So can we change it?? If yes then how??

Thanks in advance!!

Asked By: user13266902

||

Answers:

In urls.py you can change these values:

admin.site.site_header = "value1"
admin.site.site_title = "value2"
admin.site.index_title = "value3" 

More info here

Answered By: Horatiu Airbase

Yes you can change it.

And for that you have to add the following function to the admin file :

    def change_view(self, request, object_id, form_url='', extra_context=None):
        extra_context = {'title': 'Here you can type your new title for the User Change tab'}
        return super().change_view(
            request, object_id, form_url, extra_context=extra_context,
        )

So your admin file becomes :

from django.contrib import admin
from django.contrib.auth.admin import UserAdmin


from .models import CustomUser


class CustomUserAdmin(UserAdmin):

    change_list_template='change_list_form.html'

    change_form_template = 'change_form.html'

    add_form_template='add_form.html'

    list_display = ('first_name','last_name','email','is_staff', 'is_active',)
    list_filter = ('first_name','email', 'is_staff', 'is_active',)

    search_fields = ('email','first_name','last_name','a1','a2','city','state','pincode')
    ordering = ('first_name',)

    add_fieldsets = (
        ('Personal Information', {
            # To create a section with name 'Personal Information' with mentioned fields
            'description': "",
            'classes': ('wide',),  # To make char fields and text fields of a specific size
            'fields': (('first_name','last_name'),'email','a1','a2','city','state','pincode','check',
                       'password1', 'password2',)}
        ),
        ('Permissions',{
            'description': "",
            'classes': ('wide', 'collapse'),
            'fields':( 'is_staff', 'is_active','date_joined')}),
    )


    def change_view(self, request, object_id, form_url='', extra_context=None):


        extra_context = {'title': 'Here you can type your new title for the User Change tab'}


        return super().change_view(
            request, object_id, form_url, extra_context=extra_context,
        )

That’s all you have to do.

Answered By: Prateek Gupta

I had to change the title tag in base.html, now it shows up Blog as title in the browser tab:

<title>Blog{% block title %}{% endblock title %}</title>
Answered By: thomkell
Categories: questions Tags: ,
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.