My code below open two times browser tab, why?
from flask import Flask
from flask import render_template
import webbrowser
app = Flask(__name__)
@app.route("/charts")
def chart():
legend = 'Monthly Data'
labels = ["January", "February", "March", "April", "May", "June", "July", "August"]
values = [10,9,8,7,8,5,7,9]
return render_template('chart.html', values=values, labels=labels, legend=legend)
webbrowser.open('http://localhost:5000/charts')
if __name__ == "__main__":
app.run(debug=True)
I am running python 3.6 on windows 10.
Your code is running in debug mode. app.run(debug=True)
. The Flask service will initialize twice in the debug mode. When debug is off, the Flask service only initializes once.
change the last line of your code app.run(debug=True)
to app.run(debug=True, use_reloader=False)