PROJET AUTOBLOG


Sam et Max

source: Sam et Max

⇐ retour index

Templite, le moteur de template Python qui tient dans un fichier

mardi 25 février 2014 à 11:34

pip install templite

from templite import Templite
 
template = """
This is the place where all the ${variable}$ go...
The time goes fast but everything is slow...
${for woho in whohos:}$
    ${woho}$
${:end-for}$
"""
 
t = Templite(template)
print t.render(variable="junkies", whohos=["woo hoo", "woo hoo", "woo hoo hoo hoo"])

Ce qui donne :

This is the place where all the junkies go...
The time goes fast but everything is slow...

    woo hoo

    woo hoo

    woo hoo hoo hoo

Je n’ai pas écrit templite, je l’ai juste mis sur pypi et github en respectant sa paternité car il restait sous forme de snippet perdu depuis trop longtemps.

Vous pouvez le piper mais vraiment, ce n’est pas obligatoire, comme peewee et bottle, il tient dans un fichier, donc on peut juste dumper le module dans son code source.

flattr this!