我的FlaskApp中有一个ValueError(ValueError:需要解包的值太多(应为2))。 我开始知道这是因为我使用flash来显示带有类别的消息
当我尝试这样做时,问题就出现了
{% with messages = get_flashed_messages() %} {% if messages %} {% for
category, msg in messages %}
<div class="alert {{category}}">
<h1>{{category}}:</h1>
<h4>{{msg}}</h4>
</div>
{% endfor %} {% endif %} {% endwith %}
但是如果我只是从for循环中移除类别,它会工作,但是类别不工作!
{% with messages = get_flashed_messages() %} {% if messages %} {% for msg in messages %}
<div class="alert {{category}}">
<h1>{{category}}:</h1>
<h4>{{msg}}</h4>
</div>
{% endfor %} {% endif %} {% endwith %}
请帮帮我
我猜您缺少设置第二个参数,即消息的类别(可以是error
,``warning'等等) 对于视图函数中的flash()
flash(u'Invalid password provided', 'error')
不要忘记在中设置with_categories=true
{% with messages = get_flashed_messages(with_categories=true) %}
参照此单据