简体   繁体   中英

Failed to find the flaskblog error in flask

这是我得到的错误 I am trying to run flask first app.

from flask import Flask
app = Flask(__name__)

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

and I have also used export FLASK_APP=flaskblog.py

But it is constantly getting the error

Error: Failed to find Flask application or factory in module "flaskblog". Use "FLASK_APP=flaskblog:name to specify one.

You are missing the app.run which makes this a flask app. Change your flaskblog.py to the following

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.

After that, 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()

Yourre following the right steps. Just ensure that your hello.py file is saved with all the code correctly written. Save again and try again. Hope that helps.

Try using

FLASK_APP=flaskblog:name

to specify one.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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