我在GAE中有一个网站,在Jinja2模板中有一个FOR语句中的IF语句。
我使用以下方法启用了jinja2.ext.loopcontrols循环控制:
template_dir = os.path.dirname(__file__)
ENV = jinja2.Environment(loader=jinja2.FileSystemLoader(template_dir),
autoescape=True,
extensions=['jinja2.ext.autoescape',
'jinja2.ext.loopcontrols'])
我的模板如下:
{% for i in data %}
(% if i.date_posted is defined %)
{{ i.date_posted.strftime('%d %b %Y') }}
{% else %}
No
{% endif %}
{% endfor %}
我不断地发现错误:
TemplateSyntaxError: Encountered unknown tag 'endif'. Jinja was looking for the following tags: 'endfor'. The innermost block that needs to be closed is 'for'.
您没有正确声明标记
if
:请注意括号而不是大括号;它应该像这样写:
相关问题 更多 >
编程相关推荐