Supriya Ghosh (Editor)

Jinja (template engine)

Updated on
Edit
Like
Comment
Share on FacebookTweet on TwitterShare on LinkedInShare on Reddit
Original author(s)
  
Armin Ronacher

Written in
  
Python

License
  
BSD License

Development status
  
Active

Type
  
Template engine

Website
  
jinja.pocoo.org

Jinja (template engine) wwwpocooorgimagesjinjalogopng

Using python templates with jinja and google app engine


Jinja is a template engine for the Python programming language and is licensed under a BSD License created by Armin Ronacher. It is similar to the Django template engine but provides Python-like expressions while ensuring that the templates are evaluated in a sandbox. It is a text-based template language and thus can be used to generate any markup as well as sourcecode.

Contents

The Jinja template engine allows customization of tags, filters, tests, and globals. Also, unlike the Django template engine, Jinja allows the template designer to call functions with arguments on objects. Jinja is Flask's default template engine.

Section 02 lesson 15 implementing our template engine jinja2


Features

Some of the features of Jinja are:

  • sandboxed execution
  • powerful automatic HTML escaping to prevent cross-site scripting (XSS) attacks
  • template inheritance
  • compiles down to the optimal python code just in time
  • optional ahead-of-time template compilation
  • easy to debug. Line numbers of exceptions directly point to the correct line in the template.
  • configurable syntax
  • Jinja, like Smarty, also ships with an easy-to-use filter system similar to the Unix pipeline.

    Example

    Here is a small example of a template file 'example.html.jinja'

    and templating code:

    This produces the HTML string:

    References

    Jinja (template engine) Wikipedia