How to Customize Admin Site Title in Django
To customize the admin site title in Django, set the
site_header attribute of admin.site in your admin.py file. For example, use admin.site.site_header = 'My Custom Admin' to change the title shown on the admin pages.Syntax
Use the site_header attribute of the admin.site object to set a custom title for the Django admin site. This changes the text shown in the top-left corner of the admin interface.
admin.site.site_header: The main title text on the admin site.
python
from django.contrib import admin admin.site.site_header = 'Your Custom Admin Title'
Example
This example shows how to set a custom admin site title by modifying admin.py in your Django app. The admin header will display "My Project Admin" instead of the default "Django Administration".
python
from django.contrib import admin # Set a custom title for the admin site admin.site.site_header = 'My Project Admin' # Register your models below as usual # from .models import MyModel # admin.site.register(MyModel)
Output
The Django admin site header changes from "Django Administration" to "My Project Admin" on all admin pages.
Common Pitfalls
Common mistakes when customizing the admin site title include:
- Setting
site_headerin the wrong file or outsideadmin.py, so it does not take effect. - Forgetting to restart the Django development server after changes.
- Confusing
site_headerwithsite_titleorindex_title, which control different parts of the admin UI.
Make sure to place the customization code in your app's admin.py and restart the server.
python
from django.contrib import admin # Wrong: setting site_header in views.py or models.py will not work # Correct usage in admin.py admin.site.site_header = 'Correct Admin Title'
Quick Reference
Here are the main attributes to customize Django admin site text:
| Attribute | Description | Example Value |
|---|---|---|
| site_header | Text shown as the main admin site title | My Custom Admin |
| site_title | Text shown in the browser tab title | Admin Portal |
| index_title | Text shown on the admin index page | Welcome to Admin |
Key Takeaways
Set admin.site.site_header in admin.py to change the admin site title.
Restart the Django server after making changes to see updates.
Use site_title and index_title to customize other admin UI texts.
Place customization code only in admin.py for it to work properly.