I am trying to do this:
{% for movie in movie_list | sort(movie.rating) %}
But that's not right...the documentation is vague...how do you do this in Jinja2?
I am trying to do this:
{% for movie in movie_list | sort(movie.rating) %}
But that's not right...the documentation is vague...how do you do this in Jinja2?
As of version 2.6, Jinja2's built-in sort filter allows you to specify an attribute to sort by:
{% for movie in movie_list|sort(attribute='rating') %}
list_of_tuples|sort(attribute='0')
–
Billionaire reverse=True
. –
Carabineer If you want to sort in ascending order
{% for movie in movie_list|sort(attribute='rating') %}
If you want to sort in descending order
{% for movie in movie_list|sort(attribute='rating', reverse = True) %}
© 2022 - 2024 — McMap. All rights reserved.