Flask App Object
The Flask app object is the central instance you create with Flask(__name__). It holds your configuration, URL routes, and request-handling logic, and it is the WSGI application that the server runs.
Flask
Almost everything in a Flask project hangs off this single object. You register routes on it with the @app.route decorator, store settings on app.config, attach extensions to it, and finally hand it to a server like gunicorn or Werkzeug's development server.
Passing __name__ tells Flask where your application lives on disk so it can locate the templates/ and static/ folders relative to your module. In larger projects you usually create the app inside an application factory function instead of at module top level.
The variable is conventionally named app, but the name is arbitrary; what matters is that it is an instance of the Flask class and that it is importable for the server to find.
Syntax
from flask import Flask
app = Flask(__name__)Examples
Python — Run with `python app.py` then visit http://127.0.0.1:5000/
from flask import Flask
app = Flask(__name__)
@app.route("/")
def home():
return "Hello, Flask!"
if __name__ == "__main__":
app.run(debug=True)