Answer the question
In order to leave comments, you need to log in
It throws an error list indices must be integers or slices, not str on line 13, what's the problem?
I'm just starting to learn Python. I'm trying to make a 5 day forecast using the OpenWeathrMap API to display it on Django's localhost. Gives an error list indices must be integers or slices, not str on line 13. And how to implement the issue of weather on OWM for every day, and not every 3 hours.
import requests
from django.shortcuts import render
def index(request):
appid = 'd2c37acd30116d7d66777e643a1603b9'
url = 'https://api.openweathermap.org/data/2.5/forecast?q={}&units=metric&cnt=1&appid=' + appid
city = 'Москва'
res = requests.get(url.format(city)).json()
city_info = {
'city' : city,
'temp' : res["list"]["main"]["temp"],
'icon' : res["list"]["weather"]["icon"]
}
context = {'info' : city_info}
return render(request, 'weather/index.html', context)
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question