Python ValueError:太多的值无法在烧瓶中的闪蒸中解包(预期为2个)

Python ValueError:太多的值无法在烧瓶中的闪蒸中解包(预期为2个),python,flask,jinja2,Python,Flask,Jinja2,我在我的Flask应用程序中遇到ValueError(ValueError:太多的值无法解包(预期为2个))。我知道这是因为我用flash来显示一条包含类别的消息 当我尝试这个方法时,问题就出现了 {% with messages = get_flashed_messages() %} {% if messages %} {% for category, msg in messages %} <div class="alert {{category}}&

我在我的
Flask
应用程序中遇到
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 %}
{%with messages=get\u flashed\u messages()%}
{%if消息%}
{%用于类别,消息中的消息%}
{{category}}:
{{msg}}
{%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 %}
{%with messages=get\u flashed\u messages()%}
{%if消息%}
{消息%中的msg为%0}
{{category}}:
{{msg}}
{%endfor%}
{%endif%}
{%endwith%}

请帮助我

我猜您没有设置第二个参数,即查看函数中
flash()
的消息类别(可能是
错误
警告
任何..)

flash(u'Invalid password provided', 'error')
不要忘了在
get\u flashed\u messages()
函数中设置
,其中的\u categories=true

{%with messages=get_flashed_messages(with_categories=true)%}{{}--这里--}
{%if消息%}
{%用于类别,消息中的消息%}
{{category}}:
{{msg}}
{%endfor%}
{%endif%}
{%endwith%}

参考这篇

我已经知道该怎么做了,问题是我不得不提到我想在jinja中使用这个类别

{%with messages=get_flashed_messages(with_categories=true)%}

{%with messages=get\u flashed\u messages(with\u categories=true)%}
{%if消息%}
{%用于类别,消息中的消息%}
{{msg}}
{%endfor%}
{%endif%}
{%endwith%}

你能发布一下
消息的样子吗?
{% with messages = get_flashed_messages(with_categories=true) %} 
  {% if messages %} 
     {% for category, msg in messages %}
        <div class="alert {{category}}">
          <h4>{{msg}}</h4>
        </div>
     {% endfor %}
  {% endif %}
{% endwith %}