gpt4 book ai didi

python - Flask 程序可以在 Spyder 中运行/调试吗?

转载 作者:行者123 更新时间:2023-12-01 01:02:55 25 4
gpt4 key购买 nike

我正在尝试在网上找到的一个简单的 Flask 教程。这是代码:

from flask import Flask, jsonify
from flask_cors import CORS

# configuration
DEBUG = True

# instantiate the app
app = Flask(__name__)
app.config.from_object(__name__)

# enable CORS
CORS(app)

# sanity check route
@app.route('/ping', methods=['GET'])
def ping_pong():
return jsonify('pong!')

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

Spyder 中,如果我运行该文件,它工作正常。但是,我希望能够在选择语句时对其进行调试和执行。当我选择整个内容并执行(通过交互式控制台)时,出现以下错误。有办法让它工作吗?

Serving Flask app "__main__" (lazy loading)
Environment: production
WARNING: Do not use the development server in a production environment.
Use a production WSGI server instead.
Debug mode: on
Running on http://127.0.0.1:5000/ (Press CTRL+C to quit)
Restarting with stat
/opt/local/anaconda3/bin/python: can't find '__main__' module in ''
An exception has occurred, use %tb to see the full traceback.

最佳答案

为了运行的目的,使用app.run(debug = False)代替app.run()

关于python - Flask 程序可以在 Spyder 中运行/调试吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55630726/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com