2

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.

  • 1
    Flask in debug mode runs twice. See [this answer](https://stackoverflow.com/a/25504196/5652150) – aybry Sep 18 '20 at 14:58
  • Yes. so to avoid this just do change app.run(debug=True) to app.run(debug=True, use_reloader=False) – arun n a May 29 '21 at 08:47

1 Answers1

2

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)

arun n a
  • 684
  • 9
  • 26