亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

ValueError:在 Flask 的閃存中解壓的值太多(預期為 2)

ValueError:在 Flask 的閃存中解壓的值太多(預期為 2)

泛舟湖上清波郎朗 2023-02-07 16:42:30
我的應用程序中有ValueError (ValueError: too many values to unpack (expected 2))一個Flask。我開始知道這是因為我使用 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 %}請幫我
查看完整描述

2 回答

?
至尊寶的傳說

TA貢獻1789條經驗 獲得超10個贊

我猜你錯過了在你的視圖函數中設置第二個參數,消息的類別(它可以是error,warning無論如何..)flash()


flash(u'Invalid password provided', 'error')

不要忘記設置with_categories=true功能get_flashed_messages():


{% with messages = get_flashed_messages(with_categories=true) %} {# --HERE--  #}

  {% if messages %}

    {% for category, msg in messages %}


      <div class="alert {{category}}">

        <h1>{{category}}:</h1>

        <h4>{{msg}}</h4>

      </div>


    {% endfor %}

  {% endif %}

{% endwith %}


查看完整回答
反對 回復 2023-02-07
?
縹緲止盈

TA貢獻2041條經驗 獲得超4個贊

我找到了該怎么做,問題是我不得不提到我想在神社中使用類別


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


{% 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 %}


查看完整回答
反對 回復 2023-02-07
  • 2 回答
  • 0 關注
  • 113 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號