Jinja2 templates superset of Django templates?

According to the design documentation, Jinja2 templates are '[sic] modeled after Djangos templates.' I read elsewhere that Django templates can be used interchangeably with Jinja2.

So, I assume the title says it all: Jinja2 templates (strict) superset of native Django templates?

Otherwise, how do they differ? And if the differences are minor, why isn't Jinja2 a superset of Django's own templates?

+4
source share
2 answers

No, Jinja is not a strict addition to the Django template language. A good summary of the differences is provided in the documentation .

There is no particular reason why Jinja will be a superset of DTL. This means a standalone package that can be used by any Python web card. I would say that most of the differences are related to Jinja's attempt to be less restrictive and more Pythonic than DTL. For example, while DTL allows filters to accept only one argument and uses a unique character :to indicate it, Jinja allows any number of arguments and uses ordinary characters ().

, Jinja Django ( django-jinja) , . , , , DTL. Jinja.

+5

Django Jinja2 , ,

, .

Django:

{% for page in user.get_created_pages %}<br/>
    <br/>
{% endfor %}

Jinja:

{% for page in user.get_created_pages() %}<br/>
    <br/>
{% endfor %}
+4

Source: https://habr.com/ru/post/1544692/


All Articles