3๐
โ
You can use it like this with your current data structure.
{% for key, value in names.items %}
<p class="lead">Name: {{ value.0 }}</p>
<p class="lead">Id: {{ value.1 }}</p>
<p class="lead">Date: {{ value.2 }}</p>
{% endfor %}
But it would be more readable if change your data structure into this:
my_dict = {
'ant': {
'id': 2,
'name': 'abc',
'date' : datetime.now()
}
}
then your template would look like this:
{% for key, person in my_dict.items %}
<p class="lead">Id: {{ person.id }} </p>
<p class="lead">Name: {{ person.name }} </p>
<p class="lead">Date: {{ person.date }} </p>
{% endfor %}
๐คKutayAslan
2๐
In Jinja-2 you can subscript in the variables:
{% for key,vals in names.items %}
<p class="lead">Name: {{ vals[0] }}</br>
Id: {{ vals[1] }}</br>
Date: {{ vals[2] }}</p>
{% endfor %}
- [Django]-Django admin filters on remote field via get_list_filter
- [Django]-Django โ Admin โ Inline โ 'extra' value based on some condition
Source:stackexchange.com