Very cool! After trying different approaches to render HTML from Python objects (including lxml, xml, etc.) I ended up liking htpy[0] the most, and the apps I built look similar to the examples in the FastHTML docs. I'll definitely try it.
One pattern I use is putting all the functions that generate HTML inside their own class. That way, I can more easily create and reuse components like:
class Views:
...
def comp1(self):
return Div(self.header(), P("too"))
Then `self.header()` can be reused in other parts, or to return partial HTML. It also makes it easy to pass the "request" object to the class, and do conditional rendering based on it (cookies, auth, language, etc).
One pattern I use is putting all the functions that generate HTML inside their own class. That way, I can more easily create and reuse components like:
Then `self.header()` can be reused in other parts, or to return partial HTML. It also makes it easy to pass the "request" object to the class, and do conditional rendering based on it (cookies, auth, language, etc).[0]: https://htpy.dev/