Overriding Core Admin Templates
Explore techniques to safely override core Django admin templates by extending built-in blocks. Learn app-level and model-level template customizations to add UI elements like banners and buttons, ensuring maintainable and version-neutral changes to the admin layout.
We have customized the Django admin’s appearance with CSS, but CSS is not always enough. When users need new interface elements, such as a warning banner above a form or shared action buttons across the admin, we need to extend or override the admin templates.
The safer approach is to extend Django’s built-in admin templates and add custom markup inside the template blocks Django provides.
Version-neutral template discovery
Before overriding a Django admin template, we need to inspect the original template structure. In some older workflows, developers used fragile command-line scripts to locate and copy templates from the local Python site-packages directory. That approach is hard to reproduce across environments because local paths differ across operating systems and deployment setups.
Instead, we use a version-neutral strategy. We rely on the DIRS and APP_DIRS settings we configured earlier, which instruct Django to check our project's templates folder before falling back to the framework defaults. To understand the structure of the default templates, ...