CHANGES.rst
.. currentmodule:: jinja2
Unreleased
__version__ attribute. Use feature detection or
importlib.metadata.version("jinja2") instead.pyproject.toml instead of setup.cfg.
:pr:1793flit_core instead of setuptools as build backend.Released 2025-03-05
|attr filter does not bypass the environment's attribute lookup,
allowing the sandbox to apply its checks. :ghsa:cpwx-vrp4-4pq7Released 2024-12-21
str.format, such as
by passing a stored reference to a filter that calls its argument.
:ghsa:q2x7-8rv6-6q7h1792, :ghsa:gmj6-6f8f-6699clear and pop on known mutable sequence
types. :issue:2032render for an async template uses asyncio.run.
:pr:1952auto_aiter warnings. :pr:1960aclose-able AsyncGenerator from
Template.generate_async. :pr:1960root_render_func() unclosed in
Template.generate_async. :pr:19601960concat function for the current environment
when calling block references. :issue:1701|unique async-aware, allowing it to be used after another
async-aware filter. :issue:1781|int filter handles OverflowError from scientific notation.
:issue:1921{% set ... %}
call. :issue:2021copy/pickle/etc) interaction with Undefined
objects. :issue:2025copy/pickle support for the internal missing object.
:issue:2027Environment.overlay(enable_async) is applied correctly. :pr:2061FileSystemLoader includes the paths that were
searched. :issue:1661PackageLoader shows a clearer error message when the package does not
contain the templates directory. :issue:17051880urlize does not add mailto: to values like @a@b. :pr:1870@pass_context`` can be used with the ``|select`` filter. :issue:1624`set for multiple assignment (a, b = 1, 2) does not fail when the
target is a namespace attribute. :issue:1413set in all branches of {% if %}{% elif %}{% else %} blocks
does not cause the variable to be considered initially undefined.
:issue:1253Released 2024-05-05
xmlattr filter does not allow keys with / solidus, >
greater-than sign, or = equals sign, in addition to disallowing spaces.
Regardless of any validation done by Jinja, user input should never be used
as keys to this filter, or must be separately validated first.
:ghsa:h75v-3vvj-5mfjReleased 2024-01-10
1858xmlattr filter does not allow keys with spaces. :ghsa:h5c8-rqwp-cp95{% trans %} blocks
more helpful. :pr:1918Released 2022-04-28
Environment.overlay to match __init__.
:issue:1645FileSystemBytecodeCache. :issue:1654Released 2022-03-25
1637Released 2022-03-24
Drop support for Python 3.6. :pr:1534
Remove previously deprecated code. :pr:1544
WithExtension and AutoEscapeExtension are built-in now.contextfilter and contextfunction are replaced by
pass_context. evalcontextfilter and
evalcontextfunction are replaced by pass_eval_context.
environmentfilter and environmentfunction are replaced
by pass_environment.Markup and escape should be imported from MarkupSafe.Context subclasses is no longer
supported. Override resolve_or_missing instead of
resolve.unicode_urlencode is renamed to url_quote.Add support for native types in macros. :issue:1510
The {% trans %} tag can use pgettext and npgettext by
passing a context string as the first token in the tag, like
{% trans "title" %}. :issue:1430
Update valid identifier characters from Python 3.6 to 3.7.
:pr:1571
Filters and tests decorated with @async_variant are pickleable.
:pr:1612
Add items filter. :issue:1561
Subscriptions ([0], etc.) can be used after filters, tests, and
calls when the environment is in async mode. :issue:1573
The groupby filter is case-insensitive by default, matching
other comparison filters. Added the case_sensitive parameter to
control this. :issue:1463
Windows drive-relative path segments in template names will not
result in FileSystemLoader and PackageLoader loading from
drive-relative paths. :pr:1621
Released 2021-11-09
153515371514hash(Node) behavior. Nodes are hashed by id
again :issue:1521PackageLoader works when the package is a single module file.
:issue:1512Released 2021-10-04
1427compile_templates deterministic for filter and import
names. :issue:1452, 1453Undefined to act like
StrictUndefined for the in operator. :issue:14481494PackageLoader will not include a current directory (.) path
segment. This allows loading templates from the root of a zip
import. :issue:1467Released 2021-05-18
141814261433autoescape and with_
extensions shows more relevant context. :issue:1429jinja2.Markup without an argument.
Use markupsafe.Markup instead. :issue:1438render for an async template uses asyncio.new_event_loop
This fixes a deprecation that Python 3.10 introduces. :issue:1443Released 2021-05-11
Drop support for Python 2.7 and 3.5.
Bump MarkupSafe dependency to >=1.1.
Bump Babel optional dependency to >=2.1.
Remove code that was marked deprecated.
Add type hinting. :pr:1412
Use :pep:451 API to load templates with
:class:~loaders.PackageLoader. :issue:1168
Fix a bug that caused imported macros to not have access to the
current template's globals. :issue:688
Add ability to ignore trim_blocks using +%}. :issue:1036
Fix a bug that caused custom async-only filters to fail with
constant input. :issue:1279
Fix UndefinedError incorrectly being thrown on an undefined variable
instead of Undefined being returned on
NativeEnvironment on Python 3.10. :issue:1335
Blocks can be marked as required. They must be overridden at
some point, but not necessarily by the direct child. :issue:1147
Deprecate the autoescape and with extensions, they are
built-in to the compiler. :issue:1203
The urlize filter recognizes mailto: links and takes
extra_schemes (or env.policies["urlize.extra_schemes"]) to
recognize other schemes. It tries to balance parentheses within a
URL instead of ignoring trailing characters. The parsing in general
has been updated to be more efficient and match more cases. URLs
without a scheme are linked as https:// instead of http://.
:issue:522, 827, 1172, :pr:1195
Filters that get attributes, such as map and groupby, can
use a false or empty value as a default. :issue:1331
Fix a bug that prevented variables set in blocks or loops from
being accessed in custom context functions. :issue:768
Fix a bug that caused scoped blocks from accessing special loop
variables. :issue:1088
Update the template globals when calling
Environment.get_template(globals=...) even if the template was
already loaded. :issue:295
Do not raise an error for undefined filters in unexecuted
if-statements and conditional expressions. :issue:842
Add is filter and is test tests to test if a name is a
registered filter or test. This allows checking if a filter is
available in a template before using it. Test functions can be
decorated with @pass_environment, @pass_eval_context,
or @pass_context. :issue:842, :pr:1248
Support pgettext and npgettext (message contexts) in i18n
extension. :issue:441
The |indent filter's width argument can be a string to
indent by. :pr:1167
The parser understands hex, octal, and binary integer literals.
:issue:1170
Undefined.__contains__ (in) raises an UndefinedError
instead of a TypeError. :issue:1198
Undefined is iterable in an async environment. :issue:1294
NativeEnvironment supports async mode. :issue:1362
Template rendering only treats \n, \r\n and \r as line
breaks. Other characters are left unchanged. :issue:769, 952, 1313
|groupby filter takes an optional default argument.
:issue:1359
The function and filter decorators have been renamed and unified.
The old names are deprecated. :issue:1381
pass_context replaces contextfunction and
contextfilter.pass_eval_context replaces evalcontextfunction and
evalcontextfilterpass_environment replaces environmentfunction and
environmentfilter.Async support no longer requires Jinja to patch itself. It must
still be enabled with Environment(enable_async=True).
:issue:1390
Overriding Context.resolve is deprecated, override
resolve_or_missing instead. :issue:1380
Released 2021-01-31
urlize filter by reducing regex
backtracking. Email matching requires a word character at the start
of the domain part, and only word characters in the TLD. :pr:1343Released 2020-04-13
__getattr__, like
:class:~unittest.mock.Mock to be treated as a
:func:contextfunction. :issue:1145wordcount filter to trigger :class:Undefined methods
by wrapping the input in :func:soft_str. :pr:11601162AttributeError on access doesn't cause a recursion error.
:issue:1177~loaders.PackageLoader from 2.10 which
removed the dependency on setuptools and pkg_resources, and added
limited support for namespace packages. The changes caused issues
when using Pytest. Due to the difficulty in supporting Python 2 and
:pep:451 simultaneously, the changes are reverted until 3.0.
:pr:11821178namespace() assignment object in templates works in
async environments. :issue:1180lstrip_blocks is enabled. :issue:1138~nativetypes.NativeEnvironment doesn't evaluate
intermediate strings during rendering. This prevents early
evaluation which could change the value of an expression.
:issue:1186Released 2020-01-30
{{ data.items[1:] }}) in an async template. :issue:1141Released 2020-01-27
ChainableUndefined class to support getitem and
getattr on an undefined object. :issue:977{%+ syntax (with NOP behavior) when lstrip_blocks is
disabled. :issue:748default parameter for the map filter. :issue:557meta.find_undeclared_variables. :issue:931912, :pr:922923LRUCache.setdefault. :pr:1000trim filter takes an optional string of characters to trim.
:pr:828jinja2.ext.debug extension adds a {% debug %} tag to
quickly dump the current context and available filters and tests.
:issue:174, :pr:798, 983857, :pr:858{{ 2 * (3 < 5) }} outputs "2" instead of "False".
:issue:755, :pr:938boolean, false, true, integer and float
tests. :pr:824finalize function is only applied to the
output of expressions (constant or not), not static template data.
:issue:63FileSystemLoader, a template
can have the same name as a directory. :issue:821Undefined when omitting the else clause
in a {{ 'foo' if bar }} expression, regardless of the
environment's undefined class. Omitting the else clause is a
valid shortcut and should not raise an error when using
:class:StrictUndefined. :issue:710, :pr:1079loop control variables such as length and
revindex0 when looping over a generator. :issue:459, 751, 794,
:pr:993765|map filter will await the filter
call if needed. :pr:913loop attributes, the iterator is not
advanced ahead of the current iteration unless length,
revindex, nextitem, or last are accessed. This makes it
less likely to break groupby results. :issue:555, :pr:1101loop attributes length and
revindex work for async iterators. :pr:11011101~loader.PackageLoader doesn't depend on setuptools or
pkg_resources. :issue:970PackageLoader has limited support for :pep:420 namespace
packages. :issue:1097os.PathLike objects in
:class:~loader.FileSystemLoader and :class:~loader.ModuleLoader.
:issue:870~nativetypes.NativeTemplate correctly handles quotes
between expressions. "'{{ a }}', '{{ b }}'" renders as the tuple
('1', '2') rather than the string '1, 2'. :issue:1020~nativetypes.NativeTemplate directly creates a
:class:~nativetypes.NativeEnvironment instead of a default
:class:Environment. :issue:1091LRUCache.copy(), the copy's queue methods point to
the correct queue. :issue:843889|wordwrap filter treats existing newlines as separate paragraphs
to be wrapped individually, rather than creating short intermediate
lines. :issue:175break_on_hyphens parameter to |wordwrap filter.
:issue:5501108False if any
comparison returns False, rather than only the last one.
:issue:11021104763DerivedContextReference node that can be used by
extensions to get the current context and local variables such as
loop. :issue:860733TemplateSyntaxError.source is not empty when raised from an
included template. :issue:457Undefined value to get_template (such as through
extends, import, or include), raises an
UndefinedError consistently. select_template will show the
undefined message in the list of attempts rather than the empty
string. :issue:1037TemplateSyntaxError can be pickled. :pr:1117Released 2019-10-04
setup.py that was preventing
installation.Released 2019-10-04
range in the sandboxed environment uses xrange on
Python 2 to avoid memory use. :issue:9331050Released 2019-04-06
SandboxedEnvironment securely handles str.format_map in
order to prevent code execution through untrusted format strings.
The sandbox already handled str.format.Released 2017-11-08
OverlayScope which can be used
to create an unoptimized scope that will look up all variables from
a derived context.in test that works like the in operator. This can be
used in combination with reject and select.previtem and nextitem to loop contexts, providing
access to the previous/next item in the loop. If such an item does
not exist, the value is undefined.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)namespace function that creates a special object which
allows attribute assignment using the set tag. This can be used
to carry data across scopes, e.g. from a loop body to code that
comes after the loop.trimmed modifier to {% trans %} to strip linebreaks
and surrounding whitespace. Also added a new policy to enable this
for all trans blocks.random filter is no longer incorrectly constant folded and
will produce a new random choice each time the template is rendered.
:pr:478unique filter. :pr:469min and max filters. :pr:475eq, ne, lt,
le, gt, ge. :pr:665import statement cannot end with a trailing comma. :pr:617,
:pr:618indent filter will not indent blank lines by default. :pr:685reverse argument for dictsort filter. :pr:692NativeEnvironment that renders templates to native Python
types instead of strings. :pr:708set tag. :pr:489tojson filter marks output as safe to match documented behavior.
:pr:718{% elif ... %} blocks resulted in
a "too many levels of indentation" error. These blocks now compile
to native elif ..: instead of else: if ..: :issue:759Released 2017-04-03
675Released 2017-01-28
_GroupTuple because
this caused issues with ansible and it was an unintended change.
:issue:654resolve method since it was hard for people to spot that this
could cause a regression.669{% extends %} tag could not be used
with async environments. :issue:668666671Released 2017-01-10
646649651truncate.leeway default configurable to improve
compatibility with older templates.Released 2017-01-08
645641block scoped would not take advantage of
the new scoping rules. In some more exotic cases a variable
overridden in a local scope would not make it into a block.with statement to be in line
with the new scoping rules. This resolves some unlikely bugs in edge
cases. This also introduces a new internal With node that can be
used by extensions.Released 2017-01-08
640642Released 2017-01-07
Released 2017-01-07, codename Derivation
generator_stop on supported Python versions
(Python 3.5 and later)map and friends will now give better error messages if you
forgot to quote the parameter.truncate filter to support better truncation in
case the string is barely truncated at all.tojson filter from Flask to
Jinja and hooked it up with the new policy framework.safe by default.compiler.ascii_str policy.foo is divisibleby 2 or foo is divisibleby 3 as you would expect.with context and without context.with and autoescape tags are now built-in.select_autoescape function which helps configuring
better autoescaping easier.Released 2016-12-29
for_qs flag for urlencode.int to non-string values.Released 2015-07-26, codename Replacement
target parameter to urlize function.followsymlinks to the file system loader.make_logging_undefined which returns an undefined
object that logs failures into a logger.set tag.is number test to accept long integers in all Python
versions.is number to accept Decimal as a number.{% macro m(x, y=1, z) %} a syntax
error. The previous behavior for this code was broken anyway
(resulting in the default value being applied to y).jinja2.compiler.CodeGenerator and jinja2.runtime.Context by
adding two new attributes to the environment
(code_generator_class and context_class). :pr:404Released 2014-06-06
Released 2014-01-10
Debian bug 734747_ for more information... _Debian bug 734747: https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=734747
Released 2013-08-07
call_filter not working properly on environment
and context filters.Released 2013-05-20, codename Translation
urlencode filter that automatically quotes values for URL
safe usage with utf-8 as only supported encoding. If applications
want to change this encoding they can override the filter.keep-trailing-newline configuration to environments and
templates to optionally preserve the final trailing newline.last on the loop context no longer causes the iterator
to be consumed into a list.contextfunction and other decorators to be applied to
__call__.wordwrap filter.map, select, reject, selectattr and
rejectattr filters.loop.depth to figure out how deep inside a
recursive loop the code is.Released 2011-07-24, codename Convolution
Released 2010-10-18
Released 2010-10-17
Released 2010-10-17
Released 2010-08-18
--with-speedups).Released 2010-08-17
num in newstyle gettext for something else
than the pluralize count will no longer raise a :exc:KeyError.Released 2010-05-29, codename Incoherence
Released 2010-04-20
Released 2010-04-13, codename Correlation
ModuleLoader that can load templates from
precompiled sources. The environment now features a method to
compile the templates from a configured loader into a zip file or
folder.Released 2010-02-19
Released 2010-02-10, codename 3000 Pythons
360.339{% if %} a syntax error now. :issue:364Released 2009-09-14
Released 2009-09-13, codename Kong
ignore missing to skip
non existing templates.not raised. It's now possible to write not foo in bar as an alias to foo not in bar like in python. Previously
the grammar required parentheses (not (foo in bar)) which was
odd.{% call %} tag inside loops.{{ foo[1, 2] }} impossible.327331scoped modifier to blocks.meta module.Released 2008-12-25
Released 2008-11-23, codename Yasuzō
{{ foo.0.0 }}
impossible.foo.ugettext now followed by
foo.gettext if an translations object is installed. This makes
dealing with custom translations classes easier.sort filter that works like dictsort but for arbitrary
sequences.cycler.joiner.compile_expression method to the environment that allows
compiling of Jinja expressions into callable Python objects.Released 2008-07-17, codename Jinjavitus
Subscript is gone
and was replaced with Getitem and Getattr.TemplateStream.dump.{{ "foo" "bar" }} is equivalent to {{ "foobar" }}else is optional for conditional expressions. If not given it
evaluates to false.filesizeformat filter uses decimal prefixes now by default and
can be set to binary mode with the second parameter.Released 2008-06-09