7๐
โ
{{ 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.
๐คdijxtra
0๐
Iโm not sure I understand your question but to get the values form a dict in the template you can use the methods items or values.
If you use {{dict.items}} you get a list of tuples (key, value) and you can get the value simply using tuple.1.
If you use {{dict.values}} you just get a list of the values of the dictionary.
๐คFacundo Casco
- [Django]-What's the best way to map the main urls in a django project?
- [Django]-Why does Django template prevent HTML autocomplete from functioning?
- [Django]-Django Application: Foreign Key pointing to an abstract class
-1๐
I think you want:
{% with headers|slice:"1" as data %}
<a href="{{ data.url }}"{{ data.class_attr|safe }}>{{ data.text }}</a>
{% endwith %}
๐คSmileyChris
- [Django]-Django Caching โ How do I set up my code to avoid duplicating cache logic?
- [Django]-Django-allauth Uncaught ReferenceError
- [Django]-How start server Django in the VM (Vagrant)
Source:stackexchange.com