[Django]-Output sorted python dict within django template

10👍

Dictionaries are unsorted.

You will need to convert your dict to a nested list in the view: the easiest way would be just to call sorted(bdays_all.items()).

0👍

You also could create a new dictionary with sorted keys in your view:

dictio = {'a': 'orange', 'c':'apple', 'b': 'bannana'}
di = {}
for key in sorted(dictio.iterkeys()):
    di[key] = dictio[key]

whit the result:

di = {'a': 'orange', 'b': 'bannana', 'c': 'apple'}
👤doru

Leave a comment