How to flashing a message with link using Flask flash?

前端 未结 4 1553
清歌不尽
清歌不尽 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:29

    The other answers here focus on changing your template to allow all flash messages to be marked as safe, which may not be what you want.

    If you just want to mark certain flashed messages as safe, wrap the text passed to flash() in Markup(). (Flask API Docs for Markup)

    For example, instead of:

    flash('Successfully registered, please click here')
    

    Wrap the string in Markup() like this:

    flash(Markup('Successfully registered, please click here'))
    

    As always, you will need to import Markup from the flask package something like:

    from flask import Markup
    

提交回复
热议问题