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.
By extending the native <a> tag, we can simply add an is attribute to indicate it is a client-side link, so it won't make the browser go to the page specified in its href attribute when clicked.
To override the default template you first need to access the template you want to modify from the django/contrib/admin/templates/admin directory. Let's say we want to change base. html – to do so, we would copy that file and paste it into the templates/admin directory in our project.
The Django admin is a powerful built-in tool giving you the ability to create, update, and delete objects in your database using a web interface. You can customize the Django admin to do almost anything you want.
Using the extends tag in Django requires several things. (1) First, you need a Django template to extend. This is the template whose base code you want to use for other templates. (2) Next, you need to add the Django extend block content tags where each of the other templates will be loaded in.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With