Python template engine
Posted
by jturo
on Stack Overflow
See other posts from Stack Overflow
or by jturo
Published on 2010-06-02T07:05:44Z
Indexed on
2010/06/02
7:44 UTC
Read the original article
Hit count: 363
Hello there,
Could it be possible if somebody could help me get started in writing a python template engine? I'm new to python and as I learn the language I've managed to write a little MVC framework running in its own light-weight-WSGI-like server.
I've managed to write a script that finds and replaces keys for values: (Obviously this is not how my script is structured or implemented. this is just an example)
from string import Template
html = '<html>\n'
html += ' <head>\n'
html += ' <title>This is so Cool : In Controller HTML</title>\n'
html += ' </head>\n'
html += ' <body>\n'
html += ' Home | <a href="/hi">Hi ${name}</a>\n'
html += ' </body>\n'
html += '<html>'
Template(html).safe_substitute(dict(name = 'Arturo'))
My next goal is to implement custom statements, modifiers, functions, etc (like 'for' loop) but i don't really know if i should use another module that i don't know about. I thought of regular expressions but i kind feel like that wouldn't be an efficient way of doing it
Any help is appreciated, and i'm sure this will be of use to other people too.
Thank you
© Stack Overflow or respective owner