looking for template package

Gerard Flanagan grflanagan at gmail.com
Wed Mar 4 17:08:08 CET 2009


Neal Becker wrote:
> I'm looking for something to do template processing.  That is, transform 
> text making various substitutions.  I'd like to be able to do substitutions 
> that include python expressions, to do arithmetic computations within 
> substitutions.
> 
> I know there are lots of template packages, but most seem aimed at web use.  
> This is just text processing, not part of any web stuff.
> 
> Any suggestions?
> 

Here are three that I have used with success:

+ Cheetah - http://cheetahtemplate.org/
+ Mako - http://makotemplates.org/
+ Tempita - http://pythonpaste.org/tempita/

Django templates may not suit (you sir) as they are limited by design 
and won't allow python code directly.

Jinja2 is another (http://jinja.pocco.org/2/). Its syntax is based on 
Django's and initially I didn't like it for this reason, it looked like 
Django but wasn't and this confused my (admittedly small) brain. 
However, looking at it again recently, it is very well documented and 
has a lot of useful builtin filters and tests which are typically the 
sort of thing that you end up needing to use pure python blocks for 
anyway. So, even though it's the one I haven't used (and Django 
templates are still preferable for Django applications), Jinja2 ftw!

HTH

G.




More information about the Python-list mailing list