问题
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