遇到未知标签'with'

Moy*_*lin 3 django django-templates jinja2 python-2.7

我在尝试使用django 1.8"遇到未知标签"和'"的jinja2模板时遇到以下错误.

相同的模板在我的烧瓶应用程序上工作正常但是当试图使用jinja 2的with功能时,我得到了这个错误.

在jinja模板里面

{% with %}
    {% set vartest = 42 %}
    {{ vartest }}
{% endwith %}
Run Code Online (Sandbox Code Playgroud)

在我的jinja2环境定制中

def environment(**options):
    env = Environment(**options)
    env.globals.update({
        'static': staticfiles_storage.url,
        'url_for': reverse,
        'STATIC_URL': STATIC_URL
    })
    return env
Run Code Online (Sandbox Code Playgroud)

jon*_*rpe 5

with声明是Jinja 2.3版的新内容; 如果你有更早的东西,请使用pip install --upgrade Jinja2获取最新版本.

它也是一个扩展,所以你必须将它包括在内Environment,例如通过添加:

options.setdefault('extensions', []).append('jinja2.ext.with_')
Run Code Online (Sandbox Code Playgroud)