odoo15 QWeb模板中输出内容不进行html转义的处理

admin 2022-4-10 26945

在odoo15中,已经废止了 <t t-raw 标签,所以要在qweb中不转义原样输出内容不建议再使用 <t t-raw="内容"/>这种方式,根据官方的说明,要在python代码中预先把要输出的内容包装成Markup对象,再传递给qweb引擎进行渲染。

例如:

#...
show_message = "正在打印,请稍候...<br/><br/>如果打印机未输出报表,请检查康虎云报表是否已启动!<br/><br/><a href=\"cfprint://open\">启动康虎云报表</a>"
show_message = markupsafe.Markup(show_message)        # 增加这一行,把show_message包装成Markup对象
data.update( docs=docs, show_message=show_message, )
#...
return super(IrActionsReport, self)._render_qweb_html(docids, data)


参考资料:

https://www.odoo.com/documentation/15.0/developer/reference/frontend/qweb.html#reference-qweb-advanced-output

https://github.com/OCA/maintainer-tools/wiki/Migration-to-version-15.0

https://github.com/odoo/odoo/pull/70004

https://github.com/odoo/odoo/commit/01875541b1a8131cb



最新回复 (0)
返回