考虑这个简单的 Flask “hello world” 示例。
from flask import Flask
app = Flask(__name__)
@app.route("/inst")
def index():
print('Hello World!')
return "Hello World!"
if __name__ == '__main__':
app.run(debug=True, use_reloader=False)
当我在浏览器中输入路由URL时,打印语句会执行两次。 控制台的输出如下:
* Serving Flask app "main" (lazy loading)
* Environment: production
WARNING: This is a development server. Do not use it in a production deployment.
Use a production WSGI server instead.
* Debug mode: on
* Running on http://127.0.0.1:5000/ (Press CTRL+C to quit)
127.0.0.1 - - [04/Jan/2020 18:22:46] "GET /inst HTTP/1.1" 200 -
Hello World!
Hello World!
127.0.0.1 - - [04/Jan/2020 18:22:46] "GET /inst HTTP/1.1" 200 -
为什么会调用两次 GET /inst 接口?这是正常的流程吗?
curl
发送请求并查看是否发生了相同的事情?curl -v localhost:5000/inst
- nimaprint
命令被执行了两次。 - roganjosh