How to display raw html as html formatted text

98 views
Skip to first unread message

icodk

unread,
Nov 14, 2023, 6:35:04 AM11/14/23
to py4web
I have an html formatted text in a field in the database.
How do I display it as html and not as  raw html ?
in other words:
In the database the text is <b>Hello</b>
On the form I want it to show : Hello

icodk

unread,
Nov 14, 2023, 6:57:09 AM11/14/23
to py4web
Well: I found out that I can use: <p v-html="product.description"></p>
This will effectively render html tags as html

Massimo

unread,
Nov 15, 2023, 1:20:46 AM11/15/23
to py4web
That works assuming product.description is a Vue variable. In that case {{{product.description}}} also works.
If instead your HTML is in a python variable and you are using yatl templates (default in py4web) you could do [[=XML("<p>Hello</p>")]] or safer [[=XML("<p>Hello</p>", sanitize=True)]] which will remove any bad stuff that may be in the HTML.


icodk

unread,
Nov 15, 2023, 6:03:53 AM11/15/23
to py4web
Thanks for the insight
Reply all
Reply to author
Forward
0 new messages