我在Jinja2中有一个包含字典的列表,类似于:
items = [{'name':'name1', 'points':5}, {'name':'name2', 'points':7},
{'name':'name3', 'points':2}, {'name':'name4', 'points':11}]
我需要的是获得所有点数的总和,然后在稍后的某个地方打印出来。
目前我拥有的是:
{% set points = 0 -%}
{% for single_item in items -%}
{% set points = points + single_item["points"] -%}
{{points}}
{% endfor %}
{{ points }}
结果是:5 12 14 25 0
我是否有办法在循环之外获取那些分数,并且其中的值为25(循环的最后一个值)?