Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Webbrowser.Open open two tabs

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.

like image 546
Jacek Olejarczyk Avatar asked Oct 28 '25 04:10

Jacek Olejarczyk


1 Answers

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)

like image 123
arun n a Avatar answered Oct 31 '25 12:10

arun n a



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!