在调试模式下运行 Flask

问题描述 投票:0回答:1

我正在开发我的第一个 Flask 应用程序。我想做的就是确保我的 Flask 服务器在编辑 hello.py 文件后重新启动。

这是我的应用程序结构: enter image description here

这是 hello.py:

from flask import Flask 

app = Flask(__name__)

@app.route("/") 
def hello(): 
    return "Hello World"    

这是我的 .flask_env 文件:

FLASK_APP=hello.py
FLASK_DEBUG=True   

当我在调试中运行应用程序时,更多地使用

flask run --debug

我收到以下错误:

Error: Could not locate a Flask application. Use the 'flask --app' option, 'FLASK_APP' environment variable, or a 'wsgi.py' or 'app.py' file in the current directory.

我错过了什么?

python flask
1个回答
0
投票

您可以通过将其添加到

hello.py
文件的末尾来在调试模式下运行 Flask。这应该在调试模式下运行 Flask。

 if __name__ == "__main__":
    app.run(debug=True)
© www.soinside.com 2019 - 2024. All rights reserved.