Parsing JSON in Django template
django, django-templates
Solution
In your loop, you were trying to access a string with an index. So `TypeError: string indices must be integers, not str` was raised.
Consider following:
{% for objCity in cityList.cities %}
{{objCity.cityName}}
{% endfor%}
This will work.
Problem
I want to populate the data that Im getting from Webservice - JSON response in Template. My Service integration code: ``` serviceRequest = requests.get(ServiceSettings.getCitiesURL(), headers={ "Content-Type":servicesettings.JSON_CONTENT_TYPE, "Accept":servicesettings.HEADER_ACCEPT }) dataJson = serviceRequest.json () ``` Response that Im getting is ``` {"cities": [{"latitude": "21.321", "cityIdentifier": "GOOD", "cityName": "NY", "longitude": "23.23432"} , {"latitude": "1.321", "cityIdentifier": "GOOD", "cityName": "CA", "longitude": "3.23432"} ], "statusMessage": "OK", "statusCode": 200} ``` I'm trying to iterate it in DJango Tempalte (HTML) like below but am not not able to list the cityName ``` {% for objCities in cityList%} {% for objCity in objCities.citiess%} {{objCity.cityName}} {% endfor%} {% endfor%} ```