Home > Article > Backend Development > How to Override and Extend Django Admin Templates with App-Specific Extensions?
Overriding and Extending Django Admin Templates with App-Specific Extensions
Overriding Django admin templates while extending them can be a challenge when using the app_directories template loader. To address this, consider utilizing a custom template loader that supports extending templates from specific apps.
Solution: Custom Template Loader
A custom template loader such as SmartTemplates allows you to specify the template to extend within a specific app. This enables you to create your own admin/index.html template that inherits from the admin/index.html template in the admin app.
For example:
{% extends "admin:admin/index.html" %} {% block sidebar %} {{ block.super }} <div> <h1>Extra Links</h1> <a href="/admin/extra/">My Extra Link</a> </div> {% endblock %}
Usage:
Additional Notes:
The above is the detailed content of How to Override and Extend Django Admin Templates with App-Specific Extensions?. For more information, please follow other related articles on the PHP Chinese website!