Automatically generating HTML from code has many advantages (and some huge disadvantages) compared conventional templating but has been used as far back as Perl's CGI.pm with many different lisp libraries also doing the same.
If you have never used such a library I'd recommend giving it a try sometime - they're very nice in situations such as automatically generating forms or database search results (where conventional templating gets challenged) which have more display logic than HTML.
Some advantages are that it integrates more cleanly into Python code, the templates end up being smaller, you get guaranteed closed tags, and it has a significantly smaller API and thus it is easier to learn while being quite powerful (very Pythonic). It does all this without compromising on speed, legibility, or power.