Hello
I am trying to run a simple 3 day weather forecast flask app, but just can't seem to get it going right ('Unhandled Exception' ). Any insights would be appreciated:
from flask import Flask, Response, render_template
import requests
from collections import defaultdict
import sys
app = Flask(__name__)
app.config['DEBUG'] = True
path = '/home/username/username/'
if path not in sys.path:
sys.path.append(path)
@app.route('/')
def home():
r = requests.get('http://api.wunderground.com/api/myAPIkey/forecast/q/SouthAfrica/Stellenbosch.json')
data = r.json()
weather_data = defaultdict(list)
counter = 0
for day in data['forecast']['simpleforecast']['forecastday']:
date = day['date']['weekday'] + ":"
cond = "Conditions: ", day['conditions']
temp = "High: ", day['high']['celsius'] + "C", "Low: ", day['low']['celsius'] + "C"
counter += 1
weather_data[counter].append(date)
weather_data[counter].append(cond)
weather_data[counter].append(temp)
return render_template('home.html', weather_data=weather_data)
if __name__ == '__main__':
app.run(host="0.0.0.0", port=5000)
This is the smple template I am using 'home.html' :
<table>
{% for key,value in weather_data.items() %}
<tr>
<td>{{ value }}</td>
</tr>
{% endfor %}
</table>