如何自定义验证错误消息在烧瓶中
我在a 看起来像这样的:
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")
如您所见,我正在尝试在错误消息中插入HTML。 Unfortunately, the result looks like this:
How can I put html in the validation error message without it being escaped?
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?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我最终选择了第二个答案来自@patrick yoder ,因为我无法完全获得工作的
| safe
trick的技巧,而且这种方式感觉有些整洁。这就是我的代码现在的样子:
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: