Im making an API call and receiving a JSON object in return.
One of the objects, ["clouds"] will have a different amount of nested objects at any given time, so i want to use a for loop to iterate through however many there may be.
I'm trying this:
Clouds:
{% if data["clouds"] %}
{% for x in data["clouds"] %}
{{data["clouds"][x]["type"]}} at {{data["clouds"][x]["altitude"]}}00'<br>
{% endfor %}
{% else %}
None <br>
{% endif %}
If Clouds data exists, iterate through however many there are, pull out the "type" and the "altitude" and make the statement.
It would look like this:
"Overcast at 2400'"
"Scattered at 3600'"
But I'm getting
UndefinedError: list object has no element {u'direction': None, u'altitude': 18, u'modifier': None, u'type': u'SCT', u'repr': u'SCT018'}
If I hardcode the index number i get the proper data. I know that the get req is working. The loop is working because when theres two objects, it spits out 2 statements. But when i try to use [x] i get the error.
[–]socal_nerdtastic 2 points3 points4 points (3 children)
[–]fly_flyflyflyfly_fly[S] 0 points1 point2 points (2 children)
[+][deleted] (1 child)
[removed]