如何通过迭代 django 模板语言中的 uuid 列表来订购 dict?
How do I order dict by iterating list of uuids in django template language?
我正在尝试使用包含 django 中的订单 uuid 的列表来订购字典 - 我该如何将其模板化?
order = ['uuid1', 'uuid2']
data = {
u'uuid1': {
u'checked': False,
u'deleted': False,
u'last_change': u'2014-12-25 09:15:22.155000',
u'text': u'Test.'
},
u'uuid2': {
u'checked': False,
u'deleted': False,
u'last_change': u'2014-12-25 09:15:22.155000',
u'text': u'Test'
}
}
如何将其模板化?
{% for uuid in order %}
{% for key, value in data|getkey:{{uuid}} %}
{{ key }}
{{ value.deleted }}
{{ value.last_change }}
{% endfor %}
{% endfor %}
谢谢!
data = {
u'uuid1': {
u'checked': False,
u'deleted': False,
u'last_change': u'2014-12-25 09:15:22.155000',
u'text': u'Test.'
},
u'uuid2': {
u'checked': False,
u'deleted': False,
u'last_change': u'2014-12-25 09:15:22.155000',
u'text': u'Test'
}
}
order = [data['uuid2'], data['uuid2']]
然后,django 去...
{% for uuid in order %}
{% for key in uuid: %}
{{ key }}{{ uuid[key] }}
{% endfor %}
{% endfor %}
待更新:
data['uuid1']['checked'] = True
我正在尝试使用包含 django 中的订单 uuid 的列表来订购字典 - 我该如何将其模板化?
order = ['uuid1', 'uuid2']
data = {
u'uuid1': {
u'checked': False,
u'deleted': False,
u'last_change': u'2014-12-25 09:15:22.155000',
u'text': u'Test.'
},
u'uuid2': {
u'checked': False,
u'deleted': False,
u'last_change': u'2014-12-25 09:15:22.155000',
u'text': u'Test'
}
}
如何将其模板化?
{% for uuid in order %}
{% for key, value in data|getkey:{{uuid}} %}
{{ key }}
{{ value.deleted }}
{{ value.last_change }}
{% endfor %}
{% endfor %}
谢谢!
data = {
u'uuid1': {
u'checked': False,
u'deleted': False,
u'last_change': u'2014-12-25 09:15:22.155000',
u'text': u'Test.'
},
u'uuid2': {
u'checked': False,
u'deleted': False,
u'last_change': u'2014-12-25 09:15:22.155000',
u'text': u'Test'
}
}
order = [data['uuid2'], data['uuid2']]
然后,django 去...
{% for uuid in order %}
{% for key in uuid: %}
{{ key }}{{ uuid[key] }}
{% endfor %}
{% endfor %}
待更新:
data['uuid1']['checked'] = True