Jinja2 v2.10 Release Notes
Release Date: 2017-11-08 // over 6 years ago-
Primary changes
- A
NativeEnvironment
that renders Python types instead of strings.
๐ http://jinja.pocoo.org/docs/2.10/nativetypes/ - A
namespace
object that works with{% set %}
. This replaces
previous hacks for storing state across iterations or scopes.
๐ http://jinja.pocoo.org/docs/2.10/templates/#assignments - The
loop
object now hasnextitem
andprevitem
attributes, as
well as achanged
method, for the common case of outputting
something as a value in the loop changes. More complicated cases can
๐ use thenamespace
object.
๐ http://jinja.pocoo.org/docs/2.10/templates/#for
โฌ๏ธ Install or upgrade
Install from PyPI with pip:
pip install -U Jinja2
๐ Changelog
- โ Added a new extension node called
OverlayScope
which can be used to create an unoptimized scope that will look up all variables from a derived context. - โ Added an
in
test that works like the in operator. This can be used in combination withreject
andselect
. - โ Added
previtem
andnextitem
to loop contexts, providing access to the previous/next item in the loop. If such an item does not exist, the value is undefined. - โ Added
changed(*values)
to loop contexts, providing an easy way of checking whether a value has changed since the last iteration (or rather since the last call of the method) - โ Added a
namespace
function that creates a special object which allows attribute assignment using theset
tag. This can be used to carry data across scopes, e.g. from a loop body to code that comes after the loop. - โ Added a
trimmed
modifier to{% trans %}
to strip linebreaks and surrounding whitespace. Also added a new policy to enable this for alltrans
blocks. - The
random
filter is no longer incorrectly constant folded and will produce a new random choice each time the template is rendered. (#478) - โ Added a
unique
filter. (#469) - โ Added
min
andmax
filters. (#475) - โ Added tests for all comparison operators:
eq
,ne
,lt
,le
,gt
,ge
. (#665) import
statement cannot end with a trailing comma. (#617, #618)- 0๏ธโฃ
indent
filter will not indent blank lines by default. (#685) - โ Add
reverse
argument fordictsort
filter. (#692) - โ Add a
NativeEnvironment
that renders templates to native Python types instead of strings. (#708) - โ Added filter support to the block
set
tag. (#489) tojson
filter marks output as safe to match documented behavior. (#718)- Resolved a bug where getting debug locals for tracebacks could modify template context.
- ๐ Fixed a bug where having many
{% elif ... %}
blocks resulted in a "too many levels of indentation" error. These blocks now compile to nativeelif ..:
instead ofelse: if ..:
(#759)
- A