Ir al contenido
Menú
Se marcó esta pregunta
1 Responder
209 Vistas

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



Avatar
Descartar
Autor Mejor respuesta

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>')
Avatar
Descartar