我想按长度对列表进行排序,但是我不确定Jinja2是否可以:
{% for item in item_list | sort(length) %}
If item
is your custom class, you can override __lt__
and you'll be able to sort directly with the sort
filter. Since Jinja 2.6, you have a length
attribute on your item, you can do so with sort(attribute='length')
. Taken from the Jinja2 sort filter documentation
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.