Error: Could not locate a Flask application.

Error: Could not locate a Flask application.,第1张

Error: Could not locate a Flask application. You did not provide the “FLASK_APP” environment variable, and a “wsgi.py” or “app.py” module was not found in the current directory.

解决办法

set FLASK_APP=hello.py
$env:FLASK_APP = "hello.py"
flask run

解释
配置flask环境变量FLASK_APP,默认的是FLASK_APP=“app.py”。如果自己当前.py文件名不是app.py。需要在terminal框内修改。如当前运行python文件为:hello,py。修改代码如上!

错误案例

PS C:\Users\ZhaoYan\Desktop\Flask-project\flask5-migrate> flask db init
Usage: flask db init [OPTIONS]
Try 'flask db init --help' for help.

Error: Could not locate a Flask application. You did not provide the "FLASK_APP" environment variable, and a "wsgi.py" or "app.py" module was not found in the current directory.

PS C:\Users\ZhaoYan\Desktop\Flask-project\flask5-migrate> set FLASK_APP=migrate_app.py
PS C:\Users\ZhaoYan\Desktop\Flask-project\flask5-migrate> $env:FLASK_APP = "migrate_app.py"
PS C:\Users\ZhaoYan\Desktop\Flask-project\flask5-migrate> flask run
 * Serving Flask app 'migrate_app.py' (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: off
 * Running on http://127.0.0.1:5000 (Press CTRL+C to quit)
PS C:\Users\ZhaoYan\Desktop\Flask-project\flask5-migrate> flask db init
Creating directory C:\Users\ZhaoYan\Desktop\Flask-project\flask5-migrate\migrations ...  done
Creating directory C:\Users\ZhaoYan\Desktop\Flask-project\flask5-migrate\migrations\versions ...  done
Generating C:\Users\ZhaoYan\Desktop\Flask-project\flask5-migrate\migrations\alembic.ini ...  done
Generating C:\Users\ZhaoYan\Desktop\Flask-project\flask5-migrate\migrations\env.py ...  done
Generating C:\Users\ZhaoYan\Desktop\Flask-project\flask5-migrate\migrations\README ...  done
Generating C:\Users\ZhaoYan\Desktop\Flask-project\flask5-migrate\migrations\script.py.mako ...  done
Please edit configuration/connection/logging settings in 'C:\Users\ZhaoYan\Desktop\Flask-project\flask5-migrate\migrations\alembic.ini' before proceeding.
PS C:\Users\ZhaoYan\Desktop\Flask-project\flask5-migrate>

欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/langs/799034.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-05-06
下一篇 2022-05-06

发表评论

登录后才能评论

评论列表(0条)

保存