Error: Could not locate a Flask application. You did not provide the “FLASK_APP“ environment variabl

时间:2024-03-12 21:29:19

学习flask时的一些小问题汇总。

报错详情

flask环境下生成临时web可视网址时报错:
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.
Error: Could not locate a Flask application. You did not provide the “FLASK_APP“ environment variabl

解决办法

解决很简单,因为=前后多了空格,没有识别到

Set FLASK_APP=microblog.py
flask run

就可以运行了。
Error: Could not locate a Flask application. You did not provide the “FLASK_APP“ environment variabl

没有解决问题原因1:可能是文件在目录中的位置不对

附上我项目的目录,注意_init_.py文件,route.py文件都在blogapp目录下
主目录
Error: Could not locate a Flask application. You did not provide the “FLASK_APP“ environment variabl
blogapp目录
Error: Could not locate a Flask application. You did not provide the “FLASK_APP“ environment variabl
templates目录(.env文件放在此目录下)
Error: Could not locate a Flask application. You did not provide the “FLASK_APP“ environment variabl

没有解决问题原因2:可能是flask指令时打开的位置不对

Windows环境下,在cmd中Set FLASK_APP=microblog.py的话,应该打开到有此py文件的目录下,不然找不到文件。(我的文件在blogapp下,所以打开到blogapp为止)
Error: Could not locate a Flask application. You did not provide the “FLASK_APP“ environment variabl
这就是目前经历过的一些问题,后续还有问题再做更改。