Flask 在一个块中结合闪存消息的烧瓶引导

Flask 在一个块中结合闪存消息的烧瓶引导,flask,Flask,我在我的项目中使用flask bootstrap,唯一的怪癖是每个flash消息都显示在自己的块中,所以当一个页面显示3条消息时,它们会很快“堆积”起来。无论我给他们什么类别,他们都是橙色的。有没有一种方法可以覆盖该行为,并将flash消息合并到使用正确类别颜色的单个块中 这是我用来显示flash消息的代码,我正在使用twitterbootstraphtml/css/js文件,这些文件是我手动添加的。要启用类别,需要代码中的第二行。我有{%if category=='message'%},因为默

我在我的项目中使用flask bootstrap,唯一的怪癖是每个flash消息都显示在自己的块中,所以当一个页面显示3条消息时,它们会很快“堆积”起来。无论我给他们什么类别,他们都是橙色的。有没有一种方法可以覆盖该行为,并将flash消息合并到使用正确类别颜色的单个块中

这是我用来显示flash消息的代码,我正在使用twitter
bootstrap
html/css/js
文件,这些文件是我手动添加的。要启用类别,需要代码中的第二行。我有
{%if category=='message'%}
,因为默认的flash类别称为
'message'
,我想将其显示为警告。您还必须确保您的类别名称与
css
匹配。
在basic中是“成功”、“信息”、“警告”和“危险”


{%with messages=get\u flashed\u messages(with\u categories=true)%}
{%if消息%}
{%对于类别,消息中的消息%}
{%if category='消息“%”
{%else%}
{%endif%}
{{message}}
{%endfor%}
{%endif%}
{%endwith%}
要使它们都出现在一个块中,只需在div中移动模板中的for循环

{% 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 %}
{%with messages=get\u flashed\u messages(with\u categories=true)%}
{%if消息%}
{%对于类别,消息中的消息%}
{{message}}
{%endfor%} {%endif%} {%endwith%}

其中
message.0.0
用于获取第一条消息的类别。您还可以查看中的最后一个示例,了解如何将不同的消息类别组合在一起。

发布用于显示闪现消息的代码Hanks,我使用flask bootstrap flashed_messages宏成功地实现了此功能:)
{% 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 %}