【发布时间】:2016-01-16 08:59:35
【问题描述】:
我该怎么做:
x = 'id_1'
d = {'id_1':1, 'id_2':2}
print d[x]
在 django 模板中,我试过这个:
{% for field in form %}
<tr>
<th><label for="{{ field.auto_id }}" >{{ field.label }} </label></th>
<td>Some text from dict: {{context_dict.field.auto_id}} {{field}}</td>
</tr>
{% endfor %}
在 context_dict.field.auto_id 中,我需要 context_dict.[field.auto_id]
你们有什么想法吗?
【问题讨论】: