5👍
✅
The with
statement was new in version 2.3 of Jinja; if you have something earlier, use pip install --upgrade Jinja2
to get the latest version.
It’s also an extension, so you’ll have to include it in the Environment
, e.g. by adding:
options.setdefault('extensions', []).append('jinja2.ext.with_')
1👍
This can also be configured in your settings file.
TEMPLATES = [
{
'BACKEND': 'django.template.backends.django.DjangoTemplates',
'DIRS': [
'your/django/templates',
],
'APP_DIRS': True,
},
{
'BACKEND': 'django.template.backends.jinja2.Jinja2',
'DIRS': [
'your/jinja2/templates.',
],
'OPTIONS':{
'environment': 'app.project.jinja2.environment',
'extensions': ['jinja2.ext.with_']}
}
]
Source:stackexchange.com