opinions comments needed for improving a simple template engine.

Wensheng wenshengwang at gmail.com
Wed Dec 8 00:16:22 EST 2004


Hi, I wrote a small template engine called spytee.
Like any template enigne, it take a text(html) template file as input,
process the variable tags in the file, and display the resulted text.
The difference from most templates are: you can edit the template file
in the html editor(Frontpage, Dreamweaver, whatever), thus a near
Complete seperation of presentation and logic.  It's very simple and
easy, you only need 3 types of tags to control display, I don't think
most controls like 'if' 'else' 'loop', should be in a template anyway.

It also compile the template input into a python program and store it
in the cache location if the template is newer. On the next request of
displaying the same file, it will execute the cached python program to
save time.

the download is www.pytan.com/download/spytee.tar.gz
(there are 2 files: spytee.py and a sample template html file, just
unzip/untar it to a directoy and excute it to see how it work)

I borrowed some code from phpbb template( which in turn borrowed from
Phplib template and smarty template)

I'm new to Python (used perl and php a lot), so I'l need your help on
improving the speed of this thing.
I only tested it on mod_python, it's faster than PyMeld and Tinpy.
However it's slower than mod_python PSP, especially when excuting large
loops, like displaying a 1000 row table. (I didn't test large ones like
cheetah, quixote etc.)
At first I thought it was regular expression that slow it down.  But
after I get rid of re, I didn't see much improvement.
Pleasa try it, and any feedbacks is appreciated.




More information about the Python-list mailing list