Tutorials Exercises Get Certified Services Menu
Log in
Sign Up Spaces Bootcamps

Template Filter - dictsort


Sort the dictionary by year:

{% for x in cars|dictsort:"year" %}
  <p>{{ x.year }} {{ x.brand }} {{ x.model }}.</p>
{% endfor %}
Run Example »

Definition and Usage

The dictsort filter sorts a dictionary by the specified field.

The dictsort filter sorts ascending.

Use the dictsortreversed filter to sort descending.


{{ value|dictsort:fieldname }}

Template filters are defined by using a pipe | character followed by the name of the filter.

Arguments are defined by using a colon : character followed by the argument value.


Value Description
fieldname Required. The name of the field to be sorted on.