回答此问题可获得 20 贡献值,回答如果被采纳可获得 50 分。
<p>我得到了一个python dict,如下所示(由于隐私原因,重要信息被替换为“xxx”)。
我想在django模板中显示这个dict,但它应该是有序的,所以它应该以“a”开头,然后继续使用“B”而不是“H”</p>
<p>这是我的口述(简称):</p>
<pre><code>{ '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}]}
</code></pre>
<p>这是我的django模板:</p>
^{pr2}$
<p>这个很好用,但是没有顺序。但这正是我需要的。我尝试了python的sorted()函数,但没有成功。我只想订购信件。似乎微不足道,但我想不是</p>
<p>有什么想法吗?在</p>
<p>提前谢谢你!在</p>