我在启动 Flask 应用程序时遇到了问题。我正在尝试使用 Visual Studio Code 在调试模式下运行该应用程序,但它无法正常运行。
以下是主要模块代码:
import os
import sys
import logging
import argparse
import connexion
import flask
from cwsm import connexion_manager
import connector.config as lc
_CONFIG = None
path = os.path.abspath("./")
lc.initConfig(path + "/connector/config/Legic.ini")
app = connexion.FlaskApp(__name__, specification_dir=path + "/connector/config")
app.add_api("connectore.yaml")
app.run(host="0.0.0.0", port=8080,debug=True)
if __name__ == '__main__':
main()
这是调试的配置launch.json
{
"name": "Python: Flask",
"type": "python",
"request": "launch",
"module": "flask",
"env": {
"FLASK_APP": "application_hook:FlaskApp('dev')",
"FLASK_ENV": "development",
"FLASK_DEBUG": "0"
},
"args": [
"run",
"--no-debugger"
],
"jinja": true
}
问题是,每次我在调试模式下运行它时,程序都不会执行我的代码,而是显示这个错误:
Error: module 'application_hook' has no attribute 'FlaskApp'
为什么会发生?提前致谢
多一点追溯:
(.venv) PS C:\Users\fele\Documents\Git> cd 'c:\Users\fele\Documents\Git'; & 'c:\Users\fele\Documents\Git\.venv\Scripts\python.exe' 'c:\Users\fele\.vscode\extensions\ms-python.python-2020.9.112786\pythonFiles\lib\python\debugpy\launcher' '51724' '--' '-m' 'flask' 'run' '--no-debugger'
* Serving Flask app "application_hook:FlaskApp('dev')"
* Environment: development
* Debug mode: off
C:\Users\fele\Documents\Git/connector/config/Git.ini
C:\Users\fele\Documents\Git\.venv\lib\site-packages\connexion\apps\flask_app.py:96: Warning: Silently ignoring app.run() because the application is run from the flask command line executable. Consider putting app.run() behind an if __name__ == "__main__" guard to silence this warning.
self.app.run(self.host, port=self.port, debug=self.debug, **options)
Usage: python -m flask run [OPTIONS]
Error: module 'application_hook' has no attribute 'FlaskApp'
(.venv) PS C:\Users\fele\Documents\Git>