运行 Flask
运行 Flask
官方文档中,新版本的 Flask(>=0.11)
运行方式和以前有所不同,但是按照官方文档,可能会碰到坑的地方:
Error: Could not locate Flask application. You did not provide the FLASK_APP environment variable.
问题出在终端上面:
# run.py from flask import Flask app = Flask(__name__) @app.route("/") def hello(): return "Hello World!" if __name__ == "__main__": app.run(debug=True)
Linux
不用多说,直接运行:
$ export FLASK_APP=run.py $ flask run * Running on http://127.0.0.1:5000/
Windows
Windows 下的比较坑……
如果你的 Terminal 用的是 cmd
,那么运行:
> set FLASK_APP=run.py & flask run * Running on http://127.0.0.1:5000/
如果你的 Terminal 用的是 powershell
,那么运行:
> $env:FLASK_APP=".\run.py" | flask run * Running on http://127.0.0.1:5000/
相关推荐
bestallen 2020-08-17
JessePinkmen 2020-07-26
washing 2020-07-18
hzyuhz 2020-07-04
hzyuhz 2020-06-28
hzyuhz 2020-06-25
苦咖啡flask 2020-06-25
苦咖啡flask 2020-06-25
苦咖啡flask 2020-06-18
washing 2020-06-16
liuweiq 2020-06-14
wushaojun 2020-06-14
JessePinkmen 2020-06-14
kgshuo 2020-06-14
JessePinkmen 2020-06-14
bestallen 2020-06-13