2011-11-04 12 views
0

私は次の辞書を持っています。変数名は、次のように私はテンプレートに渡すdivision_total_displayDjangoテンプレート辞書が間違った順序で表示されます

 
{87L: {'name': , 
     'total': 660L, 
     'total_percentage': 39, 
     'total_right': 256L}, 
88L: {'name': , 
     'total': 660L, 
     'total_percentage': 42, 
     'total_right': 274L}, 
89L: {'name': , 
     'total': 435L, 
     'total_percentage': 34, 
     'total_right': 148L}} 

です:

return render_to_response('site/report_topic_standard_stat.html', 
     { 
      'report_date' : report_date, 
      'et_display' : et_display, 
      'stats_display' : stats_display, 
      'division_total_display' : division_total_display, 
      'school' : school, 
      'board' : board, 
      'standard' : standard, 
      'standard' : standard, 
      'subject' : subject, 
      'from_time' : from_time, 
      'term_id' : term_id, 
      'white_label' : white_label, 
     }, 
     context_instance=RequestContext(request) 

しかし、私は印刷テンプレートで{{division_total_display}}

 
{88L: {'total_right': 274L, 'total': 660L, 'total_percentage': 42, 'name': }, 
89L: {'total_right': 148L, 'total': 435L, 'total_percentage': 34, 'name': }, 
87L: {'total_right': 256L, 'total': 660L, 'total_percentage': 39, 'name': }} 

順序に注意してください - 87の代わりに88で始まります。

私はそれを87 followe dを88と89で入力してください。

答えて

1

代わりにOrderedDictをお試しください。通常のpython辞書は順序付けられていません - キー順をスクランブルするハッシュテーブルを使って実装されています。

docs for dictionaries: "キーは、キーが一意のものであるという要件を持つ、順序付けられていないキー/キーの組み合わせとして辞書を考えるのが最善です。"

+0

Great OrderDictが便利です。 –

4

辞書は順序付けられていません。代わりにネストされたリストを使用してください。

関連する問題