D
D
Dmitry Vyatkin2015-08-09 16:29:02
Django
Dmitry Vyatkin, 2015-08-09 16:29:02

How can I loop through the keys of a dictionary in a Django template where the value is a list?

Good afternoon! Through views I pass the dictionary to the template:
data = {'queryString': [], 'date': []}
In the template, you need to insert data from the dictionary into the links, this way did not work:

{% for date, queryString in data %}
        <a href="logs/{{ queryString }}">{{ date }}</a><br />
{% endfor %}

Please tell me how to do it right?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
S
sim3x, 2015-08-09
@dim137

should be formed like this

data = [
  {'queryString': foo, 'date': bar}
]

M
maximkalga, 2015-08-12
@maximkalga

{% for key in data %}
  {{ key }}
{% endfor %}

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question