Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/ssis/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何正确扩展django admin/base.html模板?_Django_Django Templates_Django Admin - Fatal编程技术网

如何正确扩展django admin/base.html模板?

如何正确扩展django admin/base.html模板?,django,django-templates,django-admin,Django,Django Templates,Django Admin,这看起来应该很简单,但我一定是做错了什么。我以前扩展过单个应用程序的管理模板,但这是我第一次尝试扩展以全面修改某些内容 我想在整个admin中更改帮助文本的颜色,因此我想扩展base.html模板的extrastyle块 因此,在我的主模板文件夹中,我创建了admin/base.html,其中包含以下代码: {% extends 'admin/base.html' %} {% block extrastyle %} {# Changing the color of the help t

这看起来应该很简单,但我一定是做错了什么。我以前扩展过单个应用程序的管理模板,但这是我第一次尝试扩展以全面修改某些内容

我想在整个admin中更改帮助文本的颜色,因此我想扩展base.html模板的extrastyle块

因此,在我的主模板文件夹中,我创建了admin/base.html,其中包含以下代码:

{% 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 %}
{%extends'admin/base.html%}
{%block extrastyle%}
{#在整个管理系统中更改帮助文本的颜色#}
救命,救命{
字体大小:10px!重要;
颜色:#f00;
}
{%endblock%}
现在,当我尝试访问管理员时,服务器完全崩溃,出现“总线10”错误。我相信这是因为它试图扩展自己。由于Django首先在我的应用程序模板文件夹中查找,因此{%extend'admin/base.html'%}首先找到了自己,世界爆炸了

但是,如果我尝试将基本html放在其他任何地方,它就不起作用。如果我把它放在我的一个应用程序中,它只对那个应用程序有效,但如果我把它放在其他任何地方,它就会被忽略


据我所知,扩展而不是覆盖django模板是一种最佳实践,因此我希望能够实现这一点。但是,如果我能做的唯一方法是重写它,那么这就是我要走的路线。

事实上,随着base.html自身的扩展,您的问题是一个无限递归循环


为了实现您想要的,您应该覆盖admin/base\u site.html(这反过来又扩展了base.html)。这样,您只能替换您感兴趣的块。

啊,这就是我要找的。非常感谢。