フィルターテンプレート用のdjango pythonコードがあります
@register.filter("dict")
def dict(dict, key):
if(dict and (key in dict)):
return dict[key]
else:
return None
私はhtmlファイルで呼び出します:
<table>
<tr><th>Mon</th></tr>
{% for item in COMP|hash:"ITEMS"|hash:"roster" %}
{{item|dict:"Roster"}}
{% endfor %}
</table>
dict は辞書オブジェクトです。しかし、私がそれを実行すると。エラーが表示されます:
argument of type 'Roster' is not iterable
問題は、テンプレートの dict オブジェクトがリストと見なされているため、反復可能ではないことだと思います。オブジェクトがリストではなく辞書であることをPythonに知らせる方法は?