Mat*_*olz 3 python sorting django templates dictionary
我有一个python dict,看起来如下(由于隐私原因,重要信息被替换为"xxx").我想在django模板中显示这个dict但它应该是有序的,所以它应该以"A"开头,然后继续用"B"代替"H"
这是我的命令(缩写):
{ 'A': [ {'birthday_date': None,
'first_name': 'Alberto',
'last_name': 'xxx',
'name': 'Alberto xxx',
'uid': xxx},
{ 'birthday_date': None,
'first_name': 'Antony',
'last_name': 'xxx',
'name': 'Antony xxx',
'uid': xxx}],
'H': [ { 'birthday_date': '08/28',
'first_name': 'Hitoshi',
'last_name': 'xxx',
'name': 'Hitoshi xxx',
'uid': xxx}],
'C': [ { 'birthday_date': '05/07/1985',
'first_name': 'Chr',
'last_name': 'xxx',
'name': 'Chr xxx',
'uid': xxx}],
'E': [ { 'birthday_date': None,
'first_name': 'Edimond',
'last_name': 'xxx',
'name': 'Edimond xxx',
'uid': xxx},
{ 'birthday_date': '08/30',
'first_name': 'Erika',
'last_name': 'xxx',
'name': 'Erika xxx',
'uid': xxx}],
'B': [ { 'birthday_date': '08/16/1987',
'first_name': 'Bhaktin',
'last_name': 'xxx',
'name': 'Bhaktin xxx',
'uid': xxx}],
'I': [ { 'birthday_date': '08/25/1987',
'first_name': 'Ivette',
'last_name': 'xxx',
'name': 'Ivette xxx',
'uid': xxx}]}
Run Code Online (Sandbox Code Playgroud)
这是我的django模板:
{% for letter, friend in bdays_all.items %}
<h2>{{ letter }}</h2>
{% for user in friend %}
...
{% endfor %}
{% endfor %}
Run Code Online (Sandbox Code Playgroud)
这很好用,但没有订购.但这就是我需要的.我尝试了python的sorted()函数,但没有任何成功.我只想订购这些信件.看起来微不足道,但我猜不是.
有任何想法吗?
非常感谢提前!
| 归档时间: |
|
| 查看次数: |
3632 次 |
| 最近记录: |