I’ve spotted two mentions of Python templates on a well known RSS lately so thought I’d throw together a quick intor of the major ones – partly for me to keep track but I thought I’d help the Pythonistas out too.
So here goes…
Mako
This is the replacement for the Myghty template system and is a bit different to all the others – I just don’t like it. In fact it looks plain awful but I guess some people love it. One thing it does have though is speed and in this group it comes a close second to Tenjin featured later on.
<%inherit file="base.html"/>
<%
rows = [[v for v in range(0,10)] for row in range(0,10)]
%>
Jinja
The winner of the nicest looking site goes to Jinja! Minimal and Japanese-y which is always good in my eyes. They have two versions available – you’ll want version 2. Its shiny. Oh!! I almost forgot to mention they happen to use the best source control system: Mercurial. All the cool kids use Mercurial.
Example:
My Webpage
{{ a_variable }As you can see its very similar to Django, which is up next…
Django
The framework has a great templating language built into that is so good that Google made it the default in their Google App Engine platform. Although it mixes logic into the engine its quite conservative compared to many others. Its one of my favourites! Though that’s likely down to me using Django exclusively for anything Python web-related. So don’t take my word for it – take Google’s!!
Archive for {{ year }}
{% for date in days %} {% ifchanged %}{{ date|date:"F" }}
{% endifchanged %} {{ date|date:"j" }} {% endfor %}
Cheetah
If you type “Python Templates” into Google then Cheetah features heavily.
So does a page on the Python site that lists all the Python template engines. Therefore making my post pointless and forcing me to dream up something special to make it worthwhile!Anyway, back to Cheetah. The entire world uses it pretty much. Or at least Reddit does and some other unknown companies. But it’s a good one – not the fastest which will be a bit of a shock considering the name but hey: The worlds a whacky place to be.
| $client.surname, $client.firstname | $client.email |
Tenjin
Now this is the one deserving of the fast name as its the fastest engine here according to (their) benchmarks. Its also available for multiple languages and keeps its speed across them all. Take a look.
| #{i} | ${item} |
reddit uses Mako templates.
Don’t forget markup- or tree-based template systems like Genshi or GHRML. They can be used to generate any textual output, but are specifically designed to make generating (X)HTML easy.