跳至內容
選單
此問題已被標幟
1 回覆
212 瀏覽次數

Hello,

In Odoo 16, I have an Html field.

I would like to add data containing html tags from a python function, like in this example:

html_field = fields.html()

def update_html_field(self):
self.html_field += '<div>First div</div><div>Second div</div>'

Actually, the html tags (in this example, the '<div>' tags) are not interpreted as html tags, and the view is not correct, showing the text '<div>First div</div><div>Second div</div>'.

Thanks in advace,

Boris



頭像
捨棄
作者 最佳答案

I find the solution.

In Odoo 16, the fields.Html are markupsafe.Markup objects and not str objects.

Then, the solution is:
self.html_field += markupsafe.Markup('<div>First div</div><div>Second div</div>')
頭像
捨棄