How to display html content through flask messages?

Where possible, a secure approach is to wrap your string in a Markup object before passing it to the template:

Python code:

from flask import Markup

message = Markup("<h1>Voila! Platform is ready to used</h1>")
flash(message)
return render_template('output.html')

Jinja2 Template:

<div class="flashes">
  {% for message in get_flashed_messages() %}
    {{ message }}
  {% endfor %}
</div>

Using {{message|safe}} will work, but also opens up the door for an attacker to inject malicious HTML or Javascript into your page, also known an an XSS attack. More info here if you’re interested.

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)