Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
jinja2 テンプレートに次のループがあります
{% for item in list if item.author == 'bob' %}
著者としてボブを持つ最初の 5 アイテムを取得しようとしています。
やってみた
{% for item in list if item.author == 'bob' and loop.index <= 5 %}
しかし、未定義のエラーが返されました。
それを機能させる方法は?
編集:
単純に式をネストできますか?、つまり
{% for item in list if item.author == 'bob' %} {% if loop.index <= 5 %} do something {% endif %} {% endfor %}