Saturday, June 22, 2013

Python templating..

So recently, I was working on a home project, where I needed to generate some configuration files. So I turned to a templating solution I've used before, Python and Cheetah

The configuration files I'm generating happen to use $ quite a bit, which is also one of the keyword tokens for Cheetah. I needed to override that token. Cheetah supports this, you can pass in a settings variable that lets you configure that token. It works. Except for one minor thing. The configuration file also happen to have lines that contained only a #. For some reason, Cheetah would remove this line in the output. Normally, that character is used for some compiler directive stuff, and I overrode that. But not matter what I did, it still removed that line.

So I started investigating other Python templating engines. It seems most of them assume that you only need templating for HTML. *sigh*. Eventually, I found Jinja. Instead of using $ for everything, it uses {{ }}. Which solves my dilemma. 

No comments:

Post a Comment