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 '}'
答案 0 :(得分:1)
{{..}}
,您没有在输出中添加值。只需将直接与变量
{% if book.author == username %}