A blogging site needs to do more than display a fixed page: it must receive requests, run Python code, and return useful responses. Flask is a lightweight Python web framework that connects URL resources to functions that build those responses. It starts small, then accommodates additional capabilities as an application grows. section 6.0 section 6.4 section 6.4.1
from flask import Flask #1
app = Flask(__name__) #2
@app.route("/") #3
def home(): #4
return "Hello World!"
The smallest working server creates a Flask app and uses a route decorator to connect the root URL to a function returning “Hello World!” section 6.4.2
After installing Flask with pip and starting the application with `flask run`, visit the development server at `http://127.0.0.1:5000/`. It waits for requests until stopped with Ctrl-C. Its built-in server is for development, not public production use. section 6.4 section 6.4.2
A route can return generated data rather than the same string every time. But embedding a large page as a Python string becomes hard to maintain. Keep page markup in separate templates and pass dynamic values to them with Flask’s Jinja2 integration. section 6.4.3 section 6.7
from flask import Flask, render_template #1
from datetime import datetime #2
app = Flask(__name__)
@app.route("/")
def home():
return render_template("index.html", now=datetime.now()) #3
This next version passes the current time from a route to `index.html`; the template supplies the page structure and displays the value. section 6.4.3
As the site grows, Flask can support sessions that carry information across requests. Registering handlers for HTTP errors such as 404 and 500 also lets an application render error pages consistent with the rest of its interface. section 8.1.1 section 11.10



