简体   繁体   中英

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.

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)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM