from collections import OrderedDict
league = {'PEDD United': {'id': 37828, 'rank': 12, 'totalpts': 307},
    'Fc Mbonabushia': {'id': 205633, 'rank': 6, 'totalpts': 356},
    'FC Slurp': {'id': 933573, 'rank': 11, 'totalpts': 312}, 'KFC_Overijse':
    {'id': 38861, 'rank': 5, 'totalpts': 362}, 'Fc Paris': {'id': 1538051,
    'rank': 2, 'totalpts': 396}}
league = OrderedDict(sorted(list(league.items()), key=lambda x: x[1]['totalpts'],
    reverse=True))
print(league)
Сортировка dict в цикле jinja2