logo4 Evolution is progress—                          
progress is creativity.        
vline

Sort a Dictionary in Django Templates

view blog view wiki view wiki view wiki

Sorting a dictionary means sorting the key and get the values accordingly. This task can be easily accomplished in any python code, but the template doe is somehow different as not all python commands are allowed. Most functions have to be realized trough pipes '|'.

This website (http://stackoverflow.com/questions/2024660/django-sort-dict-in-template) offers a simple piece of code that can be registered as a filter and called by the template through the 'sort' filter.

[Error: Macro 'code' error: code() missing 1 required positional argument: 'ext']

Update

I just realized that dictsort does the same job as described in the Django documentaton.


Tags: Software

 
   

(c) Mato Nagel, Weißwasser 2004-2024, Disclaimer