我想在一个部分中显示带有“错误”类别的flashed messages,而在另一部分中显示未分类的邮件。如果我只是询问消息with_categories=False
,我也会收到带有“错误”类别的消息。最好,我不想在我的所有邮件中添加类别。如何获取所有未分类的消息?
flash('You did something wrong', 'error')
flash('Hello')
{% with messages = get_flashed_messages(with_categories=false) %}
{% for message in messages %}
{{message}}
{% endfor %}
{% endwith %}
{% with messages = get_flashed_messages(category_filter=['error']) %}
{% for message in messages %}
{{message}}
{% endfor %}
{% endwith %}
输出
You did something wrong
Hello
You did something wrong
我希望
Hello
You did something wrong
答案 0 :(得分:3)
All messages have the default category 'message'
.获取这些消息,然后获取其他消息。
{% with messages = get_flashed_messages(category_filter=['message']) %}