2016-06-19 10 views
0

私は複数のネストされたディクテーションでデータを収集し、テンプレートに渡しています。私は、データアクセスてる私のテンプレートではDjangoテンプレートフィルタが間違ったデータを渡しています

@register.filter 
def get_item(dictionary, key): 
    return dictionary.get(key) 

::私はキーで辞書からデータを取得するための単純なフィルタを書いた私が使用している場合は

{% for location_type_id, location_type_name in location_types.items %} 
    {% with disctrict=disctricts|get_item:location_type_id %} 
     ... 
    {% endwith %} 
{% endfor %} 

を{{デバッグ}} I

{'districts': {5: {6: 'Friedrichshain'}, 7: {7: 'Kreuzberg', 8: 'Charlottenburg'}}, 
'location_types': {5: 'Bar', 7: '5'}} 

しかし、私はエラーが発生します: 'str'オブジェクトには属性 'get'がありません。フィルタの引数を表示すると、空の文字列がdictではなくfilterに渡されます。

答えて

1

おそらくエラーが発生し、テンプレートにタイプミスがあります: {% with disctrict=disctricts|get_item:location_type_id %}{% with disctrict=districts|get_item:location_type_id %}

+0

私を保存する必要があります!私はコードを見てそこに座っていた。 – Fabian

1

あなたはタイプミスがあります。変数名はdistrictsですが、テンプレートにはdisctrictsが使用されています。

関連する問題