14

This seems like it should be simple but I must be doing something wrong. I've extended admin templates for individual apps before, but this is the first time I've tried extending to modify something across the board.

I want to change the color of the help text across the entire admin, so I want to extend the extrastyle block of the base.html template.

So in my main templates folder I created admin/base.html with this code in it:

{% extends 'admin/base.html' %}

{% block extrastyle %}
    {# Changing the color of the help text across the entire admin #}
    <style>
        .help, p.help {
            font-size: 10px !important;
            color: #f00;
        }
    </style>
{% endblock %}

Now, when I try and access the admin, the server completely crashes with a 'bus 10' error. I believe this is because it is trying to extend itself. Since Django looks first in my app template folders, {% extend 'admin/base.html' %} finds itself first and the world explodes.

However, if I try placing the base html anywhere else it doesn't work. If I place it in one of my apps it works only for that app, but if I place it anywhere else it is just ignored.

From my understanding it's a best practice to extend instead of override django templates, so I would like to get this working. However if the only way I can do it is by overriding it, then that's the route I'll take.

Eric Ressler
  • 1,374
  • 1
  • 14
  • 25

1 Answers1

23

Indeed, your problem is an infinite recursion loop as base.html extends itself.

To achieve what you want you should override admin/base_site.html instead (which in turn extends base.html). That way you can replace only the blocks you're interested in.

ppetrid
  • 3,745
  • 27
  • 29