Django Customize Admin UI
How To customize Django Admin Interface
This page explains how to override Django admin and import a custom template to it. Along with the tutorial, we provide a working sample coded on top of Black Dashboard design (free version) designed by Creative-Tim.
Links & Resources
Django Black Dashboard - the product page
Django Admin Black - admin section customized using Black Design
The Basics
Django provides default pages for login, registration, 404 and 500 pages (etc) the full list can be found in the site-packages/django
folder:
To customize a template, we need to provide the page in a custom templates directory and inform Django to use it. When a template page is used, Django will try to resolve the file by scanning the templates provided by the user and after this step, it defaults to ones provided by the Django core.
Customize 404 page
The admin templates come in two directories:
admin is for the model object pages.
registration is for password changes and logging in and out.
To customize the 404
page, you need to override the right file. The relative path leading to the file has to be the same as the one being overridden. The file you’re interested in is 404.html
.
Step #1 - Create template directory
Step #2 - Update Django Settings
To use the new templates the project settings file should be updated as bellow to use it.
As mentioned before, Django will try to resolve a template file by scanning the directories defined by the user in the settings file. If nothing is found, the default version will be used from site-packages/django/contrib/admin/templates/
directory.
Step #3 - Customize 404 page
The custom version of our 404 page can be easily done by copying the default version from admin/templates/
directory and save it in the directory created in Step #2
Once we save the file, Django will use it when a 404 error case occur when users interacts with our application.
A complete example
This section explains the process of integrating Black Dashboard design (free version) to style the default admin section for Django.
Download UI Kit & Assets
Download your favorite template which usually contains css, js, images and fonts files. The sample we are using here (Black Dashboard) can be downloaded from the product page.
Please note that you may have to change the template slightly to do this. Because the relevant template must be usable for Django Admin features.
Create Your Django Project
Create a Django project and a new application inside using a descriptive name admin_black
, for instance.
Create new directories templates
, static
and templatetages
inside. The application folders structure should look as below:
Add your application (admin_black) to the INSTALLED_APPS setting of your Django project settings.py file (note it should be before 'django.contrib.admin'):
Now your application is ready to add a template. To do this, you need to add your template assets files like css, js, images and fonts in your application static folder.
The folders' structure of this section is completely arbitrary.
This is my structure and you can make your own structure.
Define new Django templates
In the previous, we added all the required information to our project. Now we want to override the Django admin template and add our template. To do this, you need to know that all Django admin template files are located at:
In this section you will see two folders that include admin and registration. As it is clear from the name, the admin folder is related to the admin templates and the registration folder is related to registration, such as password_reset_form.html, logged_out.html and etc templates.
In Django admin, to override the templates, just create the same files with the same address in your application. For example, to change the base.html, just create such a file in your application:
Note that you must pay attention to the blocks.
base.html is a file that you can start with. All other files import this file to use assets. So, you can add your own template files in it.
Note you can create your own blocks.
base.html: meta, css, fonts and etc
base.html: Javascripts, jQuery and etc.
Note that in sections head and footer I created a new block so that I can make changes to these sections on other pages.
You can also use templatetags to provide more customization like a custom sidebar
and navigation
. To do this create a new file inside the templatetags
as below:
This way you can override the Django admin template and import your own template.
Links & Resource
Django Black Dashboard - free Django product that uses the same UI Kit
Access the AppSeed platform for support and more Django Templates
Last updated