In one specific flash message, I need to use the HTML code in the Flask-admin. It is safe because it is my own message. I will post the important piece of code. I am using flask_admin.contrib.sqla.ModelView
The following code snippet is not interpretable, it is just an important piece of code, but you can easily test it in your own app. Please, do not ask me why I need to do something like this, I am asking, because I have tried several things, but nothing worked. The only thing what was working was to change flask-admin macro
messages()
and add safe
filter, but this is something I don't want to do in the flask-admin
. Any idea, please?
# override
def on_model_change(self, form, model, is_created):
if something_is_wrong():
raise CustomException(
'Something in the <b>entity</b> was wrong. Please check: ' +
'<ul><li><a href="#">this</a></li><li><a href="#">and this</a></li></ul>'
)
# override
def update_model(self, form, model):
try:
return super(CustomView, self).update_model(form, model)
except CustomException, ce:
self.session.rollback()
flash(Markup(ce.message), category='error')
return False
Override the template where flash message is rendered and put this in place
{{message|safe}}