Monday, 15 August 2011

python - Custom templating using Jinja2 -



python - Custom templating using Jinja2 -

i trying utilize jinja2 follows.

suppose,

following tags:

tags: {"world":"world", "c language": "dennis ritchie", "apple":"jobs" }

input:

hello {{ world }}, c written **{{ c language }}**, **}}** while **{{** java written {{ java }}, hola.

output:

hello world, c written dennis ritchie, **}}** while **{{** java written by, hola.

so in short there next things have do.

delimiters - {{ & }} if there no tag predefined, should set empty. if there single delimiter {{ or }} ( mean not pair) ,it should not consider tag else should printed it. tags should allow spaces.

out of 4, 1 & 2 jinja2 working fine.

from jinja2 import template t = template(input_string) t.render(context)

but 3rd & 4th, it's not working.(or mistaking.)

i found 1 template engine called "mustache" supports above 4 conditions. don't know how works in case of performance.

as jinja2 mature template engine, think it's possible customize default behaviour.

can know solution?

thnx in advance.

my primary testing shows mustache(pystache) faster jinja2. if possible please give expert opinion.

http://mustache.github.io/

https://github.com/defunkt/pystache

finally go on mustache. it's awesome template engine.

http://mustache.github.io/

for mustache build python

https://github.com/defunkt/pystache

python templates django-templates jinja2 template-engine

No comments:

Post a Comment