I'm new in Flask and I have this problem:
With this code I charge on "/" indexv2.html with a form and a IU. I change diffeent parameters like std, avg... with the form. I create a forecast simulation with python and I store this forecast in a file. indexv2.html read this file and shows a visualitzation. First time when I do it it works well and shows the correct visualitzation, second time it works well, stores the file well and the visualitzations still in the previous and if I reload the page the visualitzation changes to the correct visualitzation. How can I reload the page for see it correctly?
sim.py
from flask import Flask, render_template, request, redirect
import forecast
import time
app = Flask(__name__)
@app.route('/')
def student():
return render_template('indexv2.html')
@app.route('/result',methods = ['POST', 'GET'])
def result():
if request.method == 'POST':
result = request.form
avg=result["Avg"]
std=result["Std"]
leadTime=result["leadTime"]
sl=result["serviceLevel"]
numDays=result["numdays"]
forecastSimulation = forecast.Forecast(float(avg), float(std), float(leadTime), float(sl), int(numDays))
print avg, std, leadTime, sl, numDays
forecastSimulation.runAnalysis()
return render_template("indexv2.html",result = result)
if __name__ == '__main__':
app.run(debug = True, threaded=True)
indexv2.html
<!DOCTYPE html>
<head>
<meta charset="utf-8">
<title>Mysim</title>
<link rel="stylesheet" type="text/css" href= "{{ url_for('static',filename='style/styleIU.css') }}">
</head>
<body>
<script src="http://d3js.org/d3.v3.js"></script>
<script>
---Visualitzation
</script>
<form action = "http://localhost:5000/result" method = "POST">
<p>Avg <input type = "number" name = "Avg" step="0.01"/></p>
<p>Std <input type = "number" name = "Std" step="0.01"/></p>
<p>Lead Time <input type = "number" name = "leadTime" step="0.01"/></p>
<p>Service Level <input type ="number" name = "serviceLevel" step="0.01"/></p>
<p>Simulation num days <input type ="number" name = "numdays"/></p>
<p><input type = "submit" value = "Submit"/></p>
</form>
</html>