Change header 'Django administration' text

2019-04-29 09:15发布

问题:

I followed this question's answers to change my django admin panel title header.

I tried this:

There is an easy way to set admin site header - assign it to current admin instance in urls.py like this

admin.site.site_header = 'My admin'

But it just works when I'm running the page via Python manage.py runserver

My question is how can I change the admin title header when I'm running the site via gunicorn and nginx

回答1:

writing this code at the bottom of urls.py somehow worked:

admin.site.site_header = 'My admin'


回答2:

If you already have an admin.py file started wherein you have registered your particular models, you can simply adjust these values there.

your_app/admin.py

# Simple admin setup
from django.contrib import admin
from .models import MyModel
# Register model
admin.site.register(MyModel)
# Tweak admin site settings like title, header, 'View Site' URL, etc
admin.site.site_title = 'My App Admin'
admin.site.site_header = 'My App Admin'

You can find all the attributes here.



回答3:

follow the below steps to customize the site header and site title text of django admin login page :

1.)First import admin module in settings.py file like as below :

from django.contrib import admin

2.)In bottom of settings.py file add these lines:

admin.site.site_header = 'MY_SITE_HEADER'
admin.site.site_title = 'MY_SITE_TITLE'

The above method works in latest version of django i.e.1.11.3 till date.



回答4:

You can make changes to parts of the admin by providing a template in an admin subdir of your templates directory to override what is provided by admin.

In this case, you'd want to provide a base_site.html template. You can see what the default one looks like here: https://github.com/django/django/blob/master/django/contrib/admin/templates/admin/base_site.html