简体   繁体   English

找不到 Flask_APP 环境变量

[英]Flask_APP environment variable not found

I'm a beginner to Flask and I ran into some errors.我是 Flask 的初学者,遇到了一些错误。 about how I did not provide the Flask_APP environment variable:关于我没有提供 Flask_APP 环境变量的原因:

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.

I have this error with flask when I try and run my flask code.当我尝试运行 flask 代码时,出现 flask 错误。 My code was working at first but then when I tried running it again it had this problem.我的代码起初可以正常工作,但是当我再次尝试运行它时出现了这个问题。 I searched everywhere for help but I could only find ones about powershell. I'm currently using Ubuntu. Thank you!我到处寻找帮助,但我只能找到关于 powershell 的帮助。我目前正在使用 Ubuntu。谢谢!

In order to run a flask app using the flask command in the terminal, you need to set an environment variable in that terminal.为了在终端中使用 flask 命令运行 flask 应用程序,您需要在该终端中设置环境变量。 For example, if your app is created in my_app.py , then you need to execute the following in your terminal:例如,如果您的应用程序是在my_app.py中创建的,那么您需要在终端中执行以下操作:

export FLASK_APP=my_app.py

If you restart the terminal at any point you will need to re-export this variable.如果您在任何时候重新启动终端,您将需要重新导出此变量。

You can check if it is set in your current terminal using:您可以使用以下命令检查它是否已在当前终端中设置:

echo $FLASK_APP

which will show nothing if unset or my_app.py if set as above.如果 unset 或my_app.py设置,则不会显示任何内容。

Once in your project directory run the command below will solve your problem进入项目目录后,运行以下命令将解决您的问题

flask --app app.py db init

Where app.py is your flask application file name.其中app.py是您的 flask 应用程序文件名。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM