274

How can I change the site title Django site admin, the site header Django administration and the index title Site administration in Django Admin?

enter image description here

Super Kai - Kazuya Ito
  • 22,221
  • 10
  • 124
  • 129
samurailawngnome
  • 3,355
  • 3
  • 18
  • 17
  • This is covered in the [tutorial](https://docs.djangoproject.com/en/dev/intro/tutorial07/#customize-the-admin-look-and-feel). – djvg Dec 09 '19 at 12:19
  • The best answer is [below](https://stackoverflow.com/a/36251770/633961) – guettli Dec 15 '20 at 20:05

24 Answers24

416

As of Django 1.7 you don't need to override templates. You can now implement site_header, site_title, and index_title attributes on a custom AdminSite in order to easily change the admin site’s page title and header text. Create an AdminSite subclass and hook your instance into your URLconf:

admin.py:

from django.contrib.admin import AdminSite
from django.utils.translation import ugettext_lazy

class MyAdminSite(AdminSite):
    # Text to put at the end of each page's <title>.
    site_title = ugettext_lazy('My site admin')

    # Text to put in each page's <h1> (and above login form).
    site_header = ugettext_lazy('My administration')

    # Text to put at the top of the admin index page.
    index_title = ugettext_lazy('Site administration')

admin_site = MyAdminSite()

urls.py:

from django.conf.urls import patterns, include
from myproject.admin import admin_site

urlpatterns = patterns('',
    (r'^myadmin/', include(admin_site.urls)),
)

Update: As pointed out by oxfn you can simply set the site_header in your urls.py or admin.py directly without subclassing AdminSite:

admin.site.site_header = 'My administration'
maciek
  • 3,198
  • 2
  • 26
  • 33
Reto Aebersold
  • 16,306
  • 5
  • 55
  • 74
  • 14
    This throws a "You don't have permission to edit anything" error message when I try to access the /myadmin/. Looks like I should call .autodiscover, but Django 1.7 it's supposed to be called automatically. Any clue? – David Arcos Jul 29 '14 at 16:53
  • 7
    @DavidArcos You need to register your models at new `admin_site` that you created. Like `admin_site.register(MyModel, ModelAdmin)` – Andrey Fedoseev Aug 01 '14 at 13:06
  • 1
    If also a header in django.auth.views should be customized (that depends on `admin/base_site.html` template, e.g. password_reset) then also `extra_context` should be used in urls: e.g. `url(r'^password_reset/$', auth_views.password_reset, name='admin_password_reset', kwargs={'extra_context': {'site_header': "My administration"}})` – hynekcer Feb 18 '17 at 11:55
  • Something to know about this way is that it will only work with the standard admin pages, if on your side on another application you are adding your own admin pages (extendind the admin base template), they will always take the default "Django Administration" title. – Kedare Mar 31 '17 at 09:12
  • 2
    @oxfn If I have more than one apps, the `admin.site.site_header` configuration in which `app*/admin.py` would take effect? – nalzok May 13 '17 at 09:45
  • I got this error - django.core.exceptions.ImproperlyConfigured: Passing a 3-tuple to include() is not supported. Pass a 2-tuple containing the list of patterns and app_name, and provide the namespace argument to include() instead. – jerrymouse Sep 07 '18 at 02:59
  • If you override AdminSite, you get `you dont have permission`. To solve this issue check here out:https://docs.djangoproject.com/en/dev/ref/contrib/admin/#overriding-the-default-admin-site – Hojat Modaresi Mar 11 '20 at 10:33
253

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'

Or one can implement some header-building magic in separate method

admin.site.site_header = get_admin_header()

Thus, in simple cases there's no need to subclass AdminSite

oxfn
  • 6,590
  • 2
  • 26
  • 34
  • I added it in my `url.py` right after urlpattern. But it didn't work when I'm running the site with nginx – Ghasem Jan 22 '15 at 14:54
  • @AlexJolig nginx shouldn't be a problem. Which backenf fo you use? Did you restart it? – oxfn Feb 11 '15 at 11:22
  • 1
    The first way worked. I dont really know what was the problem at the moment. thank you – Ghasem Feb 11 '15 at 15:45
  • 7
    If you're changing the header, you'll probably also want to change the site title, which can be accomplished with: `admin.site.site_title = 'My site admin'`. – mcastle Jul 18 '15 at 21:15
  • 2
    Here is an import string to add to `urls.py`: `from django.contrib import admin` – serg Jan 04 '16 at 22:00
  • 4
    Wish I found this first... Heeding the docs, I subclassed `AdminSite` and spent a while trying to make it work with `autodiscover()` but finally thought of this solution on my own. I actually have my override in `admin.py`, which I think is cleaner since it's kept along with all the other admin-related logic – user193130 Apr 19 '16 at 00:20
  • 1
    check the list of all the attributes you can change at https://docs.djangoproject.com/en/1.11/ref/contrib/admin/#adminsite-objects – Sergio Morstabilini Apr 29 '17 at 09:32
  • 1
    even after 10 years this works, thank you. I placed it in my urls.py and it works in a custom theme. – Sebastian Sep 01 '21 at 03:12
168

In urls.py you can override the 3 most important variables:

from django.contrib import admin

admin.site.site_header = 'My project'                    # default: "Django Administration"
admin.site.index_title = 'Features area'                 # default: "Site administration"
admin.site.site_title = 'HTML title from adminsitration' # default: "Django site admin"

Reference: Django documentation on these attributes.

sunwarr10r
  • 4,420
  • 8
  • 54
  • 109
Gregory
  • 6,514
  • 4
  • 28
  • 26
  • This should be the CORRECT answer to this question. This is the most appropriated and elegant solution. – Gregory Nov 25 '20 at 12:37
  • is there's a way to having `username` of logged-in user with title of *index* for example: `admin.site.index_title = request.user.username+' Features area'` – Azhar Uddin Sheikh Jan 31 '22 at 11:00
147

Update: If you are using Django 1.7+, see the answer below.


Original answer from 2011: You need to create your own admin base_site.html template to do this. The easiest way is to create the file:

/<projectdir>/templates/admin/base_site.html

This should be a copy of the original base_site.html, except putting in your custom title:

{% block branding %}
<h1 id="site-name">{% trans 'my cool admin console' %}</h1>
{% endblock %}

For this to work, you need to have the correct settings for your project, namely in settings.py:

  • Make sure /projectdir/templates/ is added into TEMPLATE_DIRS.
  • Make sure django.template.loaders.filesystem.Loader is added into TEMPLATE_LOADERS.

See docs for more information on settings.py.

daaawx
  • 3,273
  • 2
  • 17
  • 16
user608133
  • 1,767
  • 1
  • 10
  • 3
  • 79
    Also note that you can `{% extends "admin/base.html" %}` in `//templates/admin/base_site.html`, and simply redefine the block(s) you need, i.e. `{% block branding %}...{% endblock %}`. – Arnaud Feb 09 '11 at 01:33
  • 12
    even if quite old, I want to add that you must put your app where you define this template before 'django.contrib.admin', in INSTALLED_APPS – DRC Jul 27 '13 at 07:08
  • @Arnaud, THAT is the cleanest answer – maazza Aug 26 '13 at 13:16
  • 1
    In django 1.6 python 3.3, the above works even when you don't add the `TEMPLATE_LOADER` setting. Just `TEMPLATE_DIR` is enough it seems – lukik Jan 26 '14 at 08:35
  • 12
    This is outdated as of 1.7. See Reto Aebersold's answer. – Andrew B. Aug 22 '14 at 01:24
  • 5
    Try this in url.py admin.site.site_header = 'My Administration' admin.site.index_title = ('My Admin') admin.site.site_title = ('My Admin page') – Ashish Gupta Jul 08 '17 at 16:51
72

A simple complete solution in Django 1.8.3 based on answers in this question.

In settings.py add:

ADMIN_SITE_HEADER = "My shiny new administration"

In urls.py add:

from django.conf import settings
admin.site.site_header = settings.ADMIN_SITE_HEADER
kuzavas
  • 2,156
  • 1
  • 16
  • 8
  • 7
    Is there a better place to do this than using urls.py ? – Venkat Kotra Mar 13 '16 at 20:21
  • 2
    @VenkatKotra Yes, in `admin.py`. If you don't already have it, just create it and don't forget to add `from django.contrib import admin`. – user193130 Apr 19 '16 at 00:26
  • 3
    The recommended way to import settings is via - "from django.conf import settings" (see https://docs.djangoproject.com/en/1.9/topics/settings/#using-settings-in-python-code) – yoniLavi Jul 03 '16 at 03:13
  • 1
    There is no setting that Django looks at called `ADMIN_SITE_HEADER`, the only thing that matters here is the line in `urls.py` – Flimm May 30 '18 at 07:57
  • I followed this way and have the named defined in settings first then imported into the url.py as explained above. I did the same for the login and the html title and all three worked well. ==> **in url.py:** {{ from django.conf import settings }} admin.site.site_header = settings.ADMIN_SITE_HEADER admin.site.site_title = settings.ADMIN_SITE_TITLE admin.site.index_title = settings.ADMIN_SITE_INDEX – HassanSh__3571619 Oct 11 '20 at 04:28
24

For Django 2.1.1 add following lines to urls.py

from django.contrib import admin

# Admin Site Config
admin.sites.AdminSite.site_header = 'My site admin header'
admin.sites.AdminSite.site_title = 'My site admin title'
admin.sites.AdminSite.index_title = 'My site admin index'
Ganesh
  • 3,128
  • 2
  • 17
  • 27
23

The easiest way of doing it make sure you have

from django.contrib import admin

and then just add these at bottom of url.py of you main application

admin.site.site_title = "Your App Title"
admin.site.site_header = "Your App Admin" 
21

Hope am not too late to the party, The easiest would be to edit the admin.py file.

admin.site.site_header = 'your_header'
admin.site.site_title = 'site_title'
admin.site.index_title = 'index_title'
Kevin Owino
  • 472
  • 3
  • 7
15

Simple Method is add following code in your url.py

    urlpatterns = [
    #Your URLS here
    path('admin/', admin.site.urls),
]

admin.site.site_header = 'SiteName Admin'
admin.site.site_title  = 'SiteName'
admin.site.index_title   = 'Admin'
10

As you can see in the templates, the text is delivered via the localization framework (note the use of the trans template tag). You can make changes to the translation files to override the text without making your own copy of the templates.

  1. mkdir locale

  2. ./manage.py makemessages

  3. Edit locale/en/LC_MESSAGES/django.po, adding these lines:

    msgid "Django site admin"
    msgstr "MySite site admin"
    
    msgid "Django administration"
    msgstr "MySite administration"
    
  4. ./manage.py compilemessages

See https://docs.djangoproject.com/en/1.3/topics/i18n/localization/#message-files

Community
  • 1
  • 1
Wedgwood
  • 993
  • 9
  • 10
  • 5
    This is a terrible solution. Overriding translation strings is just an awful idea. –  Aug 17 '15 at 23:31
9

From Django 2.0 you can just add a single line in the url.py and change the name.

# url.py

from django.contrib import admin 
admin.site.site_header = "My Admin Central" # Add this

For older versions of Django. (<1.11 and earlier) you need to edit admin/base_site.html

Change this line

{% block title %}{{ title }} | {{ site_title|default:_('Django site admin') }}{% endblock %}

to

{% block title %}{{ title }} | {{ site_title|default:_('Your Site name Admin Central') }}{% endblock %}

You can check your django version by

django-admin --version
Trect
  • 2,759
  • 2
  • 30
  • 35
8

There are two methods to do this:

1] By overriding base_site.html in django/contrib/admin/templates/admin/base_site.html: Following is the content of base_site.html:

{% extends "admin/base.html" %}

{% block title %}{{ title }} | {{ site_title|default:_('Django site admin') }}{% endblock %}

{% block branding %}
<h1 id="site-name"><a href="{% url 'admin:index' %}">{{ site_header|default:_('Django administration') }}</a></h1>
{% endblock %}

{% block nav-global %}{% endblock %}

Edit the site_title & site_header in the above code snippet. This method works but it is not recommendable since its a static change.

2] By adding following lines in urls.py of project's directory:

admin.site.site_header = "AppHeader"
admin.site.site_title = "AppTitle"
admin.site.index_title = "IndexTitle"
admin.site.site_url = "Url for view site button"

This method is recommended one since we can change the site-header, site-title & index-title without editing base_site.html.

8

Use format_html to allow html to be rendered, otherwise it will be just plain text.

in your main urls.py file add followings(urls.py is in the directory where settings.py exist):

from django.contrib import admin
from django.utils.html import format_html

site_header = 'Your html snippet'
admin.site.site_header = format_html(site_header)
Janaka R Rajapaksha
  • 3,585
  • 1
  • 25
  • 28
7

admin.py:

from django.contrib.admin import AdminSite

AdminSite.site_title = ugettext_lazy('My Admin')

AdminSite.site_header = ugettext_lazy('My Administration')

AdminSite.index_title = ugettext_lazy('DATA BASE ADMINISTRATION')
Avantol13
  • 1,009
  • 11
  • 21
Fakher Meddeb
  • 71
  • 1
  • 1
7

Just go to admin.py file and add this line in the file :

admin.site.site_header = "My Administration"

Prateek Gupta
  • 2,422
  • 2
  • 16
  • 30
6

First of all, you should add templates/admin/base_site.html to your project. This file can safely be overwritten since it’s a file that the Django devs have intended for the exact purpose of customizing your admin site a bit. Here’s an example of what to put in the file:

{% extends "admin/base.html" %}
{% load i18n %}

{% block title %}{{ title }} | {% trans 'Some Organisation' %}{% endblock %}

{% block branding %}
<style type="text/css">
  #header
  {
    /* your style here */
  }
</style>
<h1 id="site-name">{% trans 'Organisation Website' %}</h1>
{% endblock %}

{% block nav-global %}{% endblock %}

This is common practice. But I noticed after this that I was still left with an annoying “Site Administration” on the main admin index page. And this string was not inside any of the templates, but rather set inside the admin view. Luckily it’s quite easy to change. Assuming your language is set to English, run the following commands from your project directory:

$ mkdir locale
$ ./manage.py makemessages -l en

Now open up the file locale/en/LC_MESSAGES/django.po and add two lines after the header information (the last two lines of this example)

"Project-Id-Version: PACKAGE VERSION\n"
"Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: 2010-04-03 03:25+0200\n"
"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
"Language-Team: LANGUAGE <LL@li.org>\n"
"MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=UTF-8\n"
"Content-Transfer-Encoding: 8bit\n"

msgid "Site administration"
msgstr "Main administration index"

After this, remember to run the following command and reload your project’s server:

$ ./manage.py compilemessages

source: http://overtag.dk/wordpress/2010/04/changing-the-django-admin-site-title/

Soroosh
  • 477
  • 2
  • 7
  • 18
  • Linking to outside sites is considered bad, since the link might go bad. You are encouraged to rewrite the answer from the site here. –  Jul 14 '13 at 22:11
  • I rewrote the answer in case you don't wanna go outside site. – Soroosh Sep 28 '13 at 00:35
6

You can use these following lines in your main urls.py

you can add the text in the quotes to be displayed

To replace the text Django admin use admin.site.site_header = ""

To replace the text Site Administration use admin.site.site_title = ""

To replace the site name you can use admin.site.index_title = ""

To replace the url of the view site button you can use admin.site.site_url = ""

5

you do not need to change any template for this work you just need to update the settings.py of your project. Go to the bottom of the settings.py and define this.

admin.site.site_header = 'My Site Admin'

In this way you would be able to change the header of the of the Django admin. Moreover you can read more about Django Admin customization and settings on the following link.

Django Admin Documentation

Chitrank Dixit
  • 3,961
  • 4
  • 39
  • 59
5

You can use AdminSite.site_header to change that text. Here is the docs

YasinYA
  • 109
  • 2
  • 6
4

Since I only use admin interface in my app, I put this in the admin.py :

admin.site.site_header = 'My administration'
numahell
  • 131
  • 1
  • 2
4

You just override the admin/base_site.html template (copy the template from django.contrib.admin.templates and put in your own admin template dir) and replace the branding block.

Yuji 'Tomita' Tomita
  • 115,817
  • 29
  • 282
  • 245
3

In admin.py file just override these attributes

from django.contrib import admin

admin.site.site_header = "site header name"
admin.site.index_title = "index title name"
admin.site.site_title = "site title name"
Aashish Kumar
  • 111
  • 1
  • 5
1

You can change site title, site header and index title in Django Admin as shown below:

# "admin.py"

from django.contrib import admin

admin.site.site_title = 'My site title'
admin.site.site_header = 'My site header'
admin.site.index_title = 'My index title'

Then, these are changed as shown below:

enter image description here

In addition, you can translate them with gettext_lazy() as shown below. *gettext() doesn't work for them and you can see my answer explaining how to translate in Django:

# "admin.py"

from django.contrib import admin
from django.utils.translation import gettext_lazy as _

admin.site.site_title = _('My site title')
admin.site.site_header = _('My site header')
admin.site.index_title = _('My index title')

Then, these are translated as shown below:

enter image description here

Super Kai - Kazuya Ito
  • 22,221
  • 10
  • 124
  • 129
0

One easy method is to include the following code in the urls.py file located in your project folder.

 in urls.py add 

  admin.site.site_header  =  "Site Header here"  
  admin.site.site_title  =  "Side title"
  admin.site.index_title  =  "Index title"

For example:

from django.contrib import admin
from django.urls import path
from django.conf.urls import include
from django.conf.urls.static import static
from django.conf import settings


admin.site.site_header  =  "Hadramawt Kitchen"  
admin.site.site_title  =  "Hadramawt Kitchen"
admin.site.index_title  =  "Hadramawt Admin"

urlpatterns = [
  path('admin/', admin.site.urls),
  path('', include('food_products.urls' )),
  path('categories', include('categories.urls' )),
  path('news', include('news.urls')),
  path('weeklyOffer', include('weekly_offer.urls'))
]+ static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT)