Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Start function on run with Flask

Tags:

python

flask

I have a flask app

@app.route("/hello")
def generater():
     return "hello world"

if __name__ == '__main__':
    app.run()

My application runs fine, but i would like to know how I could make a request to http://127.0.0.1:5000/hello when I compile my code

like image 508
rabiaasif Avatar asked Sep 17 '25 17:09

rabiaasif


1 Answers

You can use webbrowser to automatically open http://localhost:5000 in a web browser when running your flask app:

import webbrowser
...

if __name__ == '__main__':
    webbrowser.open('http://localhost:5000')
    app.run()
like image 96
Edgar Ramírez Mondragón Avatar answered Sep 19 '25 05:09

Edgar Ramírez Mondragón