Routing connects a URL path to the Python function that handles a request. In Flask, a route turns a small function into a browser-accessible endpoint, linking application code with HTTP requests. section 6.4.2
A practical routing workflow grows from one endpoint to a maintainable application:
- Register a function with a route such as /. section 6.4.2
- Return content from the function so the browser can render the response. section 6.4.2
- Add functions and additional routes as the application needs more URLs. section 6.4.3
- Keep substantial HTML in templates rather than embedding large HTML strings inside route functions. section 6.4.3
A first route
The decorator @app.route("/") registers home() for the root URL. When a browser visits the server at that path, Flask calls home() and returns its "Hello World" result. The server continues waiting for incoming HTTP requests through its event loop. section 6.4.2
from flask import Flask #1
app = Flask(__name__) #2
@app.route("/") #3
def home(): #4
return "Hello World!"
Use the compact Flask listing to see the application instance, route decorator, handler function, and returned response together. section 6.4.2





















