How to override flask_admin style for all templates?

筅森魡賤 提交于 2020-12-10 16:03:53

问题


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.

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 %}

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.

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.


回答1:


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 %}


来源:https://stackoverflow.com/questions/50198659/how-to-override-flask-admin-style-for-all-templates

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!