Jinja2

Jinja2 is very similar to DTL in syntax. But it has a slightly different philosophy in certain places. For instance, in DTL the method call is implied as in the following example:

{% for post in user.public_posts %} 
    ... 
{% endfor %} 

But in Jinja2, we invoke the public_posts method similar to a Python function call:

{% for post in user.public_posts() %} 
    ... 
{% endfor %} 

This means that in Jinja2 you can call functions with arguments, unlike DTL. Refer to the Jinja2 documentation for more such subtle differences.

Jinja2 is usually chosen for the following reasons:

  • Familiarity: If your template designers are already comfortable using Jinja2
  • Whitespace control: Jinja2 has finer control over whitespace after the tags get rendered
  • Customizability ...

Get Django Design Patterns and Best Practices - Second Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.