Reputation: 138
This question has been asked multiple times and answered, but this simply doesn't work for me. My json structure is:
{
"apps": {
"app": [
{
"logAggregationStatus": "SUCCEEDED",
"runningContainers": -1,
"allocatedVCores": -1,
"clusterId": 234234,
"amContainerLogs": "url",
"id": "1",
"finalStatus": "SUCCEEDED"
}
]
}
}
I return a json response from my django view as:
def configuration(request):
response = requests.get("http://my_url/")
job = response.json()
return render_to_response("configuration.html", {"job": job})
I am able to see the response object in my configuration.html as:
<tr>
{% for app in job %}
{{ job.apps.app }}
{% endfor %}
</tr>
my problem is I'm not able to iterate through the remaining. I want app.id, app.finalStatus. I cannot access jobs.apps.app.id. I'm only able to access until app and not any further.
Can anyone please please help me out?
Upvotes: 1
Views: 401
Reputation: 25539
Your app
contains a list of dict, so you need to loop on the list and get each dict:
<tr>
{% for app in job.apps.app %}
{{ app.id }}
{{ app.finalStatus }}
{% endfor %}
</tr>
Upvotes: 1