【发布时间】:2010-12-02 11:49:25
【问题描述】:
在视图中:
return render_to_response('template.html',
{'headers': list(sort_headers.headers()) },
context_instance=RequestContext(request))
在模板中:
{{ headers }}
<br />
{{ headers|slice:"1" }}
在浏览器中:
[{'url': '?ot=desc&o=0', 'text': 'Nombre', 'class_attr': ' class="sorted ascending"', 'sortable': True}, {'url': '?ot=asc&o=1', 'text': 'Valor', 'class_attr': '', 'sortable': True}, {'url': '?ot=asc&o=2', 'text': 'Inventario', 'class_attr': '', 'sortable': False}, {'url': '?ot=asc&o=3', 'text': 'Fecha Creacion', 'class_attr': '', 'sortable': True}]
[{'url': '?ot=desc&o=0', 'text': 'Nombre', 'class_attr': ' class="sorted ascending"', 'sortable': True}]
我得到一个带有{{ headers|slice:"1" }} 的列表节点,但是现在,如何获得一个字典值?例如“url”返回'?ot=desc&amp;o=0'。
注意:不能使用{% for %}。
【问题讨论】: