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).[0]: https://htpy.dev/