Home » Python » python – Running Flask on bash: Could not import "app"-Exceptionshub

python – Running Flask on bash: Could not import "app"-Exceptionshub

Posted by: admin February 24, 2020 Leave a comment

Questions:

I made this code on Flask:

from flask import Flask

app = Flask(__name__)

@app.route('/')
def index():
    return "hi"

Even so, fi I try to run it with flask run it shows this message:

* Serving Flask app "app.py"
 * Environment: production
   WARNING: This is a development server. Do not use it in a production deployment.
   Use a production WSGI server instead.
 * Debug mode: off
Usage: flask run [OPTIONS]

Error: Could not import "app".

What am I doing wrong?

Edit:
App structure:

website/
  | - app.py
How to&Answers:
from flask import Flask

app = Flask(__name__)

@app.route('/')
def index():
    return "hi"


if __name__ == '__main__':
  app.run(host='0.0.0.0', port=30006, debug=True)

Run in the same directory where this code is placed.

python3 file_name.py

You can access it on

http://0.0.0.0:30006/

Working screenshot