pip install genshi
python
import genshi
html
<!-- template.html -->
<html>
<head>
<title>${title}</title>
</head>
<body>
<h1>${heading}</h1>
<ul>
<li py:for="item in items">
${item}
</li>
</ul>
</body>
</html>
python
from genshi.template import MarkupTemplate
template = MarkupTemplate(open('template.html', 'rb'))
data = {
'title': 'Genshi Demo',
'heading': 'Welcome to Genshi',
'items': ['Item 1', 'Item 2', 'Item 3']
}
output = template.generate(**data).render('xhtml')
print(output)