jinja2:html转义变量 [英] jinja2: html escape variables

查看:95
本文介绍了jinja2:html转义变量的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



我可以在模板中执行它,还是必须在python代码中完成?



我有一个可能包含da< ngero> u& s字符的变量。如何在jinja2中避免使用

解决方案

例如

  {{user.username | e}} 

通过 | e 过滤器



Jinija:模板设计器文档 - >内置过滤器:Escape


how do I html-escape dangerous unsanitized input in jinja2?

Can I do it inside the template or must it be done in python code?

I have a variable that may contain da<ngero>u&s chars. How do I escape it in jinja2

解决方案

e.g.

{{ user.username|e }}

Pipe it through the |e filter

Jinija: Template Designer Documentation -> Builtin Filters: Escape

这篇关于jinja2:html转义变量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆