Hello,
I am trying to display sunrise from the below dict file but I would get the value: 1618358103 only but i need to display sunrise instead. please review the below code along with Django views.py file.
=================views.py=============================
def homeView(request):
views = {}
city = “Kathmandu”
url = f"http://api.openweathermap.org/data/2.5/weather?q={city} &appid=dd799068b7ecc1b7446b9588d15e7e0e"
data = requests.get(url).json()
# print(data)
payload = {‘city’: data[‘name’],
‘weather’ : data[‘weather’][0][‘main’],
‘icon’: data[‘weather’][0][‘icon’],
‘kelvin_temperature’: data[‘main’][‘temp’],
‘celcius_temperature’: data[‘main’][‘temp’] - 273,
‘pressure’: data[‘main’][‘pressure’],
‘humidity’: data[‘main’][‘humidity’],
‘sunrise’: data[‘sys’] [‘sunrise’]
}
my_dict2 = {'data': payload}
date = datetime.datetime.now()
date = date.strftime("%c")
my_dict = {'date_msg': date}
views['navbar'] = navbar.objects.all()
return render(request, 'index.html', context={'date_msg': date, 'data': payload})
=====================index.html===================================
-
{{data.celcius_temperature}}ºc,Sunny{{data.humidity}} {**{data.sunrise}}**
-
{{date_msg}}
output: 1618358103 instead i need to print sunrise which is key.