Flask-Bootstrap在一个块中结合了闪存消息 [英] Flask-Bootstrap combining flash message in one block
问题描述
这是我用来显示Flash消息的代码,我正在使用twitter bootstrap
html / css / js
我手动添加的文件。要启用类别,您需要代码中的第二行。我有 {%if category =='message'%}
,因为默认的flash类别被称为'message'
我想将其作为警告显示。您还必须确保您的类别名称与 css
类
匹配。基本类是'success','info','warning'和'danger' /rel =nofollow> bootstrap主题。
< div>
{%with messages = get_flashed_messages(with_categories = true)%}
{%if messages%}
{%for category,message in message%}
{%if category = ='message'%}
< div class =alert alert-warningrole =alert>
{%else%}
< div class =alert alert - {{category}}role =alert>
{%endif%}
{{message}}
< / div>
{%endfor%}
{%endif%}
{%endwith%}
< / div>
为了让它们全部出现在一个块中,您只需要将模板中的for循环。
$ p $ {code $ {%with messages = get_flashed_messages(with_categories = true)%}
{%if messages% }
< div class =alert alert - {{messages.0.0}}role =alert>
{%用于类别,信息中的信息%}
{{信息}}< / br>
{%endfor%}
< / div>
{%endif%}
{%endwith%}
c $ c> message.0.0 是获得第一条消息的类别。您还可以查看 flash示例中的最后一个示例。 a>看看如何将不同的消息分类在一起。 I'm using flask-bootstrap in my project, and the only quirk left is that each flash message gets displayed in their own block, so they "pile-up" pretty fast when a page display 3 messages. And always in the orange color, no matter what category I gave them. Is there a way to override that behavior and combine flash message in a single block that use the right color of the category? This is the code I use to display flash messages, I am using twitter To get them all to appear within one block you simply have to move the for-loop in the template within the div. Where 这篇关于Flask-Bootstrap在一个块中结合了闪存消息的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!bootstrap
html/css/js
files which I manually added. To enable the categories you need the second line in the code. I have the {% if category == 'message' %}
because the default flash category is called 'message'
and I want to display that as a warning. You also have to make sure that your category names match the css
classes
. The classes
are 'success', 'info', 'warning' and 'danger' in the basic bootstrap theme. <div>
{% with messages = get_flashed_messages(with_categories=true) %}
{% if messages %}
{% for category, message in messages %}
{% if category == 'message' %}
<div class="alert alert-warning" role="alert">
{% else %}
<div class="alert alert-{{ category }}" role="alert">
{% endif %}
{{ message }}
</div>
{% endfor %}
{% endif %}
{% endwith %}
</div>
{% with messages = get_flashed_messages(with_categories=true) %}
{% if messages %}
<div class="alert alert-{{ messages.0.0 }}" role="alert">
{% for category, message in messages %}
{{ message }} </br>
{% endfor %}
</div>
{% endif %}
{% endwith %}
message.0.0
is to get the category of the first message. You can also look at the last example in the flash examples to see how to group together different message categories.