如何在Django admin中更改用户更改页面的标题/页面标题

我正在使用Django,并且我想在Django管理员的User Change Page中更改标题,在图片中用红色标记:

enter image description here

我的admin.py文件是这样的:

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


from .models import CustomUser


class CustomUserAdmin(UserAdmin):

    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')}),
    )

那么应该怎么做才能改变这种状况呢?

提前致谢!!

评论
  • 任性
    任性 回复

    要做到这一点,首先将以下行添加到您的管理文件中:

    change_form_template = 'change_form.html'
    

    这样您的管理文件如下所示:

    from django.contrib import admin
    from django.contrib.auth.admin import UserAdmin
    
    
    from .models import CustomUser
    
    
    class CustomUserAdmin(UserAdmin):
    
        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')}),
        )
    

    After that go to templates folder and create a html file with name : change_form.html and add following code to it:

    {% extends "admin/change_form.html" %}
    {% load i18n admin_urls static admin_modify %}
    
    {% block content_title %}
    
    <h1>Type here your new header for the User change page</h1>
    
    {% endblock %}
    

    那就是你要做的。