For example, let’s say I want to modify the breadcrumbs block of the admin/change_list.html template in the Django admin. If I try to override this template like this:
{% extends "admin/change_list.html" %}
{% block breadcrumbs %} ... my changes ... {% endblock %}
then Django goes into an infinite recursion when trying to load my override, because the “extends” tag tries to load the override rather than the original template.
An obvious way would be to copy & paste the entire source template, but this is exactly the thing I’m trying to avoid. So how can I modify a template without copying and pasting all of it into my project?
The complete details on overriding the admin templates are here: http://docs.djangoproject.com/en/dev/ref/contrib/admin/#overriding-admin-templates.
If you’re only trying to change the template for a single app, you can simply save it as
app_label/change_list.html. If you’re trying to change it for a single model, you can save it asapp_label/model_as_underscores/change_list.html.If you’re trying to change it for all your stuff, you can create a new template with a different name, and set its name as the
change_list_templateattribute on all yourModelAdminsubclasses. (OnModelAdmin, you can do the same thing withchange_form_template,delete_confirmation_template, andobject_history_template. On anAdminSite, you can override theindex_templateandlogin_templateattributes in the same way.)Both of these methods will allow you to extend from the original admin templates.