【发布时间】:2018-01-20 16:09:27
【问题描述】:
return render_template('books.html', username=session['username'], mybooks=q)
<html>
Welcome {{username}}
{% for book in mybooks %}
{% if book.author == {{username}}%}
<p>Author: {{ book.author }}</p>
<p>Edition: {{book.edition}}</p>
{% endif %}
{% endfor %}
</html>
我不明白为什么我尝试比较时会出错:
{% if book.author == {{username}}%}
错误信息:
jinja2.exceptions.TemplateSyntaxError: expected token ':', got '}'
【问题讨论】:
-
为什么要把
username括在大括号中?你不能在“逻辑”代码中做,只有if book.author == username应该是你需要的