如何覆盖所有模板的flask_admin样式? [英] How to override flask_admin style for all templates?

查看:176
本文介绍了如何覆盖所有模板的flask_admin样式?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在开发简单的Web应用程序,对于数据库显示,我使用 Flask_admin 模块. 我想将自定义CSS应用于所有模板,例如自定义海军与蓝色边框.这就是我的index.html模板的样子:

I'm working on simple web application and as for DB display I use Flask_admin module. I would like to apply custom CSS to all my templates e.g. Custom navar with blue border. This is how my index.html template looks like:

{% block head %}
    {{ super() }}
.navbar {
  border-color: #019ced;
  border-width: 1px;
  border-radius: 0;
  border-bottom-left-radius: 20px;
  border-bottom-right-radius: 20px;
  border-top: none;
  box-shadow: none;
}
{% endblock %}

它工作正常,但我想将此自定义导航栏样式应用于所有模板.

It works fine but I would like to apply this custom navbar style to all templates.

我正在尝试使用master.html

I was trying to do this using master.html

{% extends 'admin/base.html' %}
{% block head_css %}
{{ super() }}
.navbar {
  border-color: #019ced;
  border-width: 1px;
  border-radius: 0;
  border-bottom-left-radius: 20px;
  border-bottom-right-radius: 20px;
  border-top: none;
  box-shadow: none;
 }
 {% endblock %}

,然后在 index.html 中将其扩展,但没有成功. 我想我可以为从父级继承的每个视图定义自定义模板,并覆盖其中包含自定义navbar的CSS文件的标题部分,但我正在寻找更简单的方法.

and then extending from it in index.html without any success. I guess I could define custom templates for each view inherit from parent and override head section in which I include CSS file with custom navbar but I'm looking for easier way.

请让我知道从基本模板定义,创建和继承的正确方法是什么,我可以在其中定义自定义CSS.预先谢谢你.

Please let me know what is the proper way to define, create and inherit from base template in which I can define my custom CSS. Thank You in advance.

推荐答案

您的master.html文件应如下所示:

Your master.html file should look like the following:

{% extends admin_base_template %}
{% block head_css %}
    {{ super() }}
    <style>
        .navbar {
            border-color: #019ced;
            border-width: 1px;
            border-radius: 0;
            border-bottom-left-radius: 20px;
            border-bottom-right-radius: 20px;
            border-top: none;
            box-shadow: none;
        }
    </style>
{% endblock %}

这篇关于如何覆盖所有模板的flask_admin样式?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆