[英]Failed to find the flaskblog error in flask
I am trying to run flask first app.
我正在尝试运行 Flask 第一个应用程序。
from flask import Flask
app = Flask(__name__)
@app.route("/")
def hello():
return 'Hello world!'
and I have also used export FLASK_APP=flaskblog.py
我也用过
export FLASK_APP=flaskblog.py
But it is constantly getting the error但它不断收到错误
Error: Failed to find Flask application or factory in module "flaskblog".
错误:无法在模块“flaskblog”中找到 Flask 应用程序或工厂。 Use "FLASK_APP=flaskblog:name to specify one.
使用 "FLASK_APP=flaskblog:name 指定一个。
You are missing the app.run which makes this a flask app.你缺少 app.run 这使得它成为一个烧瓶应用程序。 Change your flaskblog.py to the following
将您的flaskblog.py 更改为以下内容
from flask import Flask
app = Flask(__name__)
@app.route("/")
def hello():
return 'Hello world!'
if __name__ == '__main__':
app.run()
Please run " export FLASK_APP=flaskblog.py
" from the directory where your source code exist.请从源代码所在的目录运行“
export FLASK_APP=flaskblog.py
”。
After that, run " flask run
".之后,运行“
flask run
”。
I noticed that your export was done from a different directory.我注意到您的导出是从不同的目录完成的。
Remove this if you have (in this case, you do have):如果您有(在这种情况下,您确实有),请删除它:
if name == ' main ': app.run()如果名称== ' main ': app.run()
Yourre following the right steps.你遵循正确的步骤。 Just ensure that your hello.py file is saved with all the code correctly written.
只需确保您的 hello.py 文件与正确编写的所有代码一起保存。 Save again and try again.
再次保存并重试。 Hope that helps.
希望有帮助。
Try using尝试使用
FLASK_APP=flaskblog:name
to specify one.指定一个。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.