Override Django Admin Template In 3rd Party Package?
I am developing a Python package which includes a Django addon app. The package is related to authentication so I wanted to extend the django.contrib.admin
login page.
Is it possible for my 3rd party package to override another 3rd party package?
The template for the login page is under django/contrib/admin/templates/admin/login.html
. Which means the template is registered as admin/login.html
.
I put my overridden template in my package's templates/admin/login.html
directory but the template does not get overridden.
The order of my package and Django contrib admin in INSTALLED_APPS
, template app dirs = true don't seem to change this.
It should consider the order of your template loaders (https://docs.djangoproject.com/en/1.10/ref/templates/api/#loader-types) and the order of your INSTALLED_APPS
.
From what I remember, you will need to use the django.template.loaders.app_directories.Loader
. APP_DIRS=True
should only work if you have the default loaders specified. If you have a custom list of loaders, you will need to add the loader to the list.
Then you will need to put your app before the django.contrib.admin
app, so that it will be searched for the template first.