Import Context Behavior
By default, included templates are passed the current context and importedtemplates are not. The reason for this is that imports, unlike includes,are cached; as imports are often used just as a module that holds macros.
This behavior can be changed explicitly: by adding with context_or _without context to the import/include directive, the current contextcan be passed to the template and caching is disabled automatically.
Here are two examples:
{% from 'forms.html' import input with context %}
{% include 'header.html' without context %}
Note
In Jinja 2.0, the context that was passed to the included templatedid not include variables defined in the template. As a matter offact, this did not work:
{% for box in boxes %}
{% include "render_box.html" %}
{% endfor %}
The included template renderbox.html
is _not able to accessbox in Jinja 2.0. As of Jinja 2.1, renderbox.html
_is ableto do so.