admin管理员组文章数量:1317565
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))
本文标签: pythonHow to get the generated HTML in FastHTMLStack Overflow
版权声明:本文标题:python - How to get the generated HTML in FastHTML? - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1742008134a2412379.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
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