使用Flask运行时启动功能

rab*_*sif 1 python flask

我有一个烧瓶应用

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

if __name__ == '__main__':
app.run()
Run Code Online (Sandbox Code Playgroud)

我的应用程序运行正常,但是我想知道在编译代码时如何向http://127.0.0.1:5000/hello发出请求

Edg*_*gón 5

运行flask应用程序时,可以使用webbrowser自动http://localhost:5000在Web浏览器中打开:

import webbrowser
...

if __name__ == '__main__':
    webbrowser.open('http://localhost:5000')
    app.run()
Run Code Online (Sandbox Code Playgroud)