1
웹 사이트가 GAE에서 호스팅되고 Jinja2 템플릿 내에서 FOR 문에 IF 문이 있습니다.Jinja2의 for 문에 대한 문이
내가 사용하여 내 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'.
아! 모든 것을 그렇게 단순하게. 어쩌면 새로운 안경을 얻을 때가 있습니다. :) 감사! –
@JasperJohns : 어떤 편집자를 사용하십니까? Textmate와 Sublime Text에 대해 [Jinja2 구문 번들] (http://stackoverflow.com/questions/22870627/sublime-text-syntax-highlight-jinja2)을 사용하면 더 명확한 차이를 만들 수 있습니다. –
Aptana Studio 3을 사용하고 있는데, Sublime Text는 무료입니까? 나는 그것을 보았고 나는 지금까지 많이 좋아한다. 제안 해 주셔서 감사합니다! –