Is Jinja2 documentation out of date?

风流意气都作罢 提交于 2020-01-23 16:40:25

问题


I am getting 2 errors by doing simple things that follow the documentation here http://jinja.pocoo.org/docs/templates/ :

{% if lang == 'fr' %}
   bonjour
{% elif lang == 'en' %}
   hello
{% endif %}

TemplateSyntaxError: Invalid block tag: 'elif', expected 'else' or 'endif'

and

{% extends "skeleton.html" %}

{% block a_name %}
{{ super() }}
I am extended
{% endblock %}

where skeleton.html contains {% block a_name %} hi I am skeleton {% endblock %}

TemplateSyntaxError: Could not parse the remainder: '()' from 'super()

Any clue on that ? Thanks


回答1:


I was using jinja2 with Google App Engine. Well, I thought I was doing so, but a closer look to the exception and the file stack trace, showed that it said "django".

For future reference, doing

self.response.write(template.render(template_values))

will make appengine render the template with django. Even if it says jinja2/latest in app.yaml under libraries.

You must import jinja2 and explicitly use template = jinja2.get_environment... to make it work. See https://developers.google.com/appengine/docs/python/gettingstartedpython27/templates?hl=fr for more info

Thanks for setting me on the track @Blender



来源:https://stackoverflow.com/questions/20306640/is-jinja2-documentation-out-of-date

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!