Reputation: 4047
clients_list
{'clients': [
{'id': 357995, 'value': 1.0},
{'id': 369743, 'value': 0.9}
]}
{% try %}
{% if clients_list %}
{% for client in clients_list %}
{% for user in client %}
{% raw user.id %}
{% raw user.value %}
{% end %}
{% end %}
{% end %}
{% except %}
{% end %}
Output expected:
357995
1.0
369743
0.9
The problem is that loop in template is wrong. How can i access the id and value?
This is a tornado template, but i think that is similar to django.
Update:
{% try %}
{% if clients_list %}
{% for client in clients_list %}
{% raw client %} // outputs the clients_list
{% for user in client %}
{% raw user %} outputs 'clients'
{% end %}
{% end %}
{% end %}
{% except %}
{% end %}
Upvotes: 1
Views: 114
Reputation: 4047
Here is the solution.
{% try %}
{% if clients_list %}
{% for client in clients_list %}
{% for user in client['clients'] %}
{% raw user['id'] %}
{% raw user['value'] %}
{% end %}
{% end %}
{% end %}
{% except %}
{% end %}
Upvotes: 1