问题
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