htpy: Generate HTML in Python
github.com·1d·
Discuss: Hacker News
🌀Brotli Internals
Preview
Report Post

htpy - HTML in Python

htpy is a library that makes writing HTML in plain Python fun and efficient, without a template language.

Define HTML in Python:

from htpy import body, h1, head, html, li, title, ul

menu = ["egg+bacon", "bacon+spam", "eggs+spam"]

print(
html[
head[title["Today's menu"]],
body[
h1["Menu"],
ul(".menu")[(li[item] for item in menu)],
],
]
)

And Get HTML:

<!DOCTYPE html>
<html>
<head>
<title>Today's menu</title>
</head>
<body>
<h1>Menu</h1>
<ul class="menu">
<li>egg+bacon</li>
<li>bacon+spam</li>
<li>eggs+spam</li>
</ul>
</body>
</html>

Motivation for This Project

At Personalkollen, where htpy was originally developed we often found ourselves hitting walls when using classic templates. htpy was …

Similar Posts

Loading similar posts...