Skip to Content
Меню
Вам необхідно зареєструватися, щоб взаємодіяти зі спільнотою.
Це запитання позначене
1 Відповісти
485 Переглядів

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>')
Аватар
Відмінити