Jinja (Template engine)

From Wikipedia, the free encyclopedia

Jinja is a template engine for the Python programming language. It's similar to the Django template engine but provides python like expressions while ensuring that the templates are evaluated in a sandbox. It's a text based template language thus it can be used to generate any markup as well as sourcecode. It's licensed under a BSD License. Unlike Django it's not possible to add custom tags because Jinja templates are compiled into cacheable python bytecode on the fly.

It also ships an easy to use filter system like Smarty does, similar to the Pipeline system of Unix.

[edit] Example =========================

Here is a small example of a template:

from jinja import from_string

tmpl = from_string(u'''\
<html>
<head><title>{{ variable|escape }}</title></head>
<body>
{% for item in list %}
   {{ item }}{% if not loop.last %},{% endif %}
{% endfor %}
</body>
</html>''')

print tmpl.render(
    variable='Value with <unsafe> data',
    list=[1, 2, 3, 4, 5, 6]
)

[edit] External links