Flask – Error: While importing ‘app’, an ImportError was raised

We Are Going To Discuss About Flask – Error: While importing ‘app’, an ImportError was raised. So lets Start this Python Article.

Flask – Error: While importing ‘app’, an ImportError was raised

  1. How to solve Flask – Error: While importing 'app', an ImportError was raised

    If your typing here is correct, the error is that the importet module is misspelled (Flask must be uppecase).
    Here the correct way:
    from flask import Flask app = Flask(__name__) @app.route("/") def index(): return "Hello Wolford" @app.route("/greeting/") def greeting(): return "Nice to see you"

  2. Flask – Error: While importing 'app', an ImportError was raised

    If your typing here is correct, the error is that the importet module is misspelled (Flask must be uppecase).
    Here the correct way:
    from flask import Flask app = Flask(__name__) @app.route("/") def index(): return "Hello Wolford" @app.route("/greeting/") def greeting(): return "Nice to see you"

Solution 1

If your typing here is correct, the error is that the importet module is misspelled (Flask must be uppecase).
Here the correct way:

from flask import Flask

app = Flask(__name__)

@app.route("/")
def index():
    return "Hello Wolford"

@app.route("/greeting/")
def greeting():
    return "Nice to see you"

Original Author GerritKruse Of This Content

Solution 2

This error is also emitted when there’s an error in an imported module. A good way to start debugging such errors is to directly run the file with python (without flask run). Do not forget to call the app function. Just add the following lines if you are using Flask’s Application Factory pattern.

if __name__ == "__main__":
    create_app().run()

After that run the app: python app.py

Original Author sbmthakur Of This Content

Conclusion

So This is all About This Tutorial. Hope This Tutorial Helped You. Thank You.

Also Read,

ittutorial team

I am an Information Technology Engineer. I have Completed my MCA And I have 4 Year Plus Experience, I am a web developer with knowledge of multiple back-end platforms Like PHP, Node.js, Python and frontend JavaScript frameworks Like Angular, React, and Vue.

Leave a Comment