Get list values in a Django Template
django, django-templates
Solution
{{ headers.1.url }}
From http://docs.djangoproject.com/en/dev/topics/templates/#variables:
Technically, when the template system encounters a dot, it tries the following lookups, in this order:
* Dictionary lookup
* Attribute lookup
* Method call
* List-index lookup
So, instead of {{ headers|slice:"1" }} you can do {{ headers.1 }}. And then to access the url key, you just append it: {{ headers.1.url }}.
HTH.
Problem
In view: ``` return render_to_response('template.html', {'headers': list(sort_headers.headers()) }, context_instance=RequestContext(request)) ``` In template: ``` {{ headers }} <br /> {{ headers|slice:"1" }} ``` In browser: ``` [{'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}] ``` I get a list node with `{{ headers|slice:"1" }}`, but now, how to get a dict value? for example 'url' returns `'?ot=desc&o=0'`. Note: Cant use `{% for %}`.