环保运行最小化Flask应用程序时未设置变量 [英] Env. Variables not set while running Minimal Flask application

查看:56
本文介绍了环保运行最小化Flask应用程序时未设置变量的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试按照以下链接提供的Windows机器上的flask文档: http://flask.pocoo.org/docs/0.11/quickstart/#debug -模式

I am trying to follow the flask documentation on my windows machine given at the following link: http://flask.pocoo.org/docs/0.11/quickstart/#debug-mode

首先,我在python脚本中编写了以下代码:

Firstly I wrote the code below in a python script:

from flask import Flask
app = Flask(__name__)

@app.route("/")
def hello():
    return "Hello World!"

if __name__ == "__main__":
    app.run(debug=True)

我将其保存在名为run.py

然后在命令窗口中编写以下命令:

Then wrote this command in the command window:

set FLASK_APP = run.py 
flask run

运行此命令时,出现以下错误:

Upon running this, I am getting the following error:

"Error: Could not locate flask application. You did not provide the FLASK_APP environment variable"

我原本希望得到这个:

Running on http://127.0.0.1:5000/

有人可以告诉我如何解决此问题吗?

Can somebody tell me how to fix this?

推荐答案

在使用PowerShell时,我遇到了相同的问题,并且该修复程序对我有效:
而不是使用set FLASK_APP = run.py,请尝试$env:FLASK_APP = "run.py"

I faced the same issue while using PowerShell and that fix worked for me:
instead of using set FLASK_APP = run.py, try $env:FLASK_APP = "run.py"

这篇关于环保运行最小化Flask应用程序时未设置变量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆