FastHTML returns HTML code in the response. But I want to know the generated HTML without using the response.
Best with an example:
from fasthtml import common as fh
my_var=fh.P('This is a simple example!')
How do I get the HTML content of my_var
?
FastHTML returns HTML code in the response. But I want to know the generated HTML without using the response.
Best with an example:
from fasthtml import common as fh
my_var=fh.P('This is a simple example!')
How do I get the HTML content of my_var
?
2 Answers
Reset to default 3You can use to_xml
function from the same import to convert fasthtml
components into their HTML representation.
Thanks to @user459872 and @globglogabgalab, the enclosed code is less error prune and now more simple. Here is the only missing line of code to obtain the generated HTML
from fasthtml import common as fh
my_var=fh.P('This is a simple example!')
print(fh.to_xml(my_var))
print(to_xml(my_var))
?.to_xml
comes from the same import – user459872 Commented Jan 29 at 9:14from x import *
syntax, as it populates your namespace with possibly many things, is not very efficient, and doesn't allow you to keep track what was imported from where which prevents looking efficiently for help or doc. – globglogabgalab Commented Jan 29 at 9:55