Issue
I have a custom validator in a Flask-WTF form
that looks like this:
def is_some_condition_true(arg: str) -> bool:
return arg == "example"
def validation_func(self, arg: str) -> None:
if not is_some_condition_true(arg):
raise ValidationError("The <strong>validation</strong> failed")
As you can see, I'm trying to insert html in the error message. Unfortunately, the result looks like this:
How can I put html in the validation error message without it being escaped?
Solution
I ended up going with the second answer from the question kindly pointed out by @Patrick Yoder, as I couldn't quite get the |safe
trick to work and it just feels a bit tidier this way.
This is how my code looks like now:
from markupsafe import Markup
def is_some_condition_true(arg: str) -> bool:
return arg == "example"
def validation_func(self, arg: str) -> None:
if not is_some_condition_true(arg):
error_msg = Markup("The <strong>validation</strong> failed")
raise ValidationError(error_msg)
Answered By - 965311532
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.