以下的例子是不可以的, obj.field obj只能是model instance,字典对象不可以
python dict_data = { 'key1': 0, 'key2': 1, }
template {{ dict_data.key1 }}
对策:
编写tag
custom_filter @register.filter def get_value(value, key): if (key in value.keys()): return value[key] else: return None
template {% load custom_filter %} {{ dict_data|get_value:dict_key }}
标签:template,value,filter,dict,key,data,字典 From: https://www.cnblogs.com/lxgbky/p/17557597.html