← Flask tutorial

Flask

Introduction to Flask

Flask is a "micro" Python web framework — unlike Django, it doesn't ship an ORM or admin site by default. It gives you routing and request handling, and you add whatever else you need (a database layer, forms) as separate packages, chosen deliberately rather than bundled in.

Example: the smallest complete Flask app

from flask import Flask

app = Flask(__name__)

@app.route("/")
def home():
    return "Hello, world!"

if __name__ == "__main__":
    app.run(debug=True)
Hello, world!

That's a genuinely complete, runnable web application in nine lines — Flask's minimalism is exactly why it's a popular choice for small APIs and services where you want fine control over what's included, rather than Django's more complete, more opinionated "batteries included" approach.

Example
from flask import Flask

app = Flask(__name__)

@app.route("/")
def home():
    return "Hello, world!"

if __name__ == "__main__":
    app.run(debug=True)
Output
Hello, world!