How do you sort a list in Jinja2?

后端 未结 3 783
轻奢々
轻奢々 2020-12-03 00:06

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

3条回答
  •  南方客
    南方客 (楼主)
    2020-12-03 00:44

    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) %}
    

提交回复
热议问题