How to flashing a message with link using Flask flash?

前端 未结 4 1410
清歌不尽
清歌不尽 2021-02-19 04:34

I\'m creating a web app using Flask to deal with GoogleOpenID, these codes are almost finished, except the flashing message contains a link:

@oid.after_login
def         


        
4条回答
  •  说谎
    说谎 (楼主)
    2021-02-19 05:22

    You need to render a template after calling flash() which should then get the message using get_flashed_messages(). You need to adjust your code to call a template after calling flash(). flash sends the message to next request which can be extracted by the template. The template can look something like:

    {% with messages = get_flashed_messages() %}
        {% if messages %}
        
      {% for message in messages %}
    • {{ message | safe }}
    • {% endfor %}
    {% endif %} {% endwith %}

    In your view code, I would add a render_template right after the flash() call. Something like:

    flash('success')
    return render_template('whatever.html')   
    

提交回复
热议问题