Route

A mapping from a URL path to the function that runs when someone visits it.

In a web framework, a route connects a URL path like /about to a function (a view function) that builds the response. In Flask you create one with the @app.route("/path") decorator placed above the function.

When a request arrives, the framework reads the path, finds the matching route, runs its function, and sends back whatever it returns.

Example
from flask import Flask
app = Flask(__name__)

@app.route("/about")     # this route maps /about to about()
def about():
    return "About this site"

Where this shows up in real Python

Routes connect URLs to view functions — the map that decides which code runs for /, /about, or /users/42.

Commonly used Route tools

  • @app.route('/path') — bind a URL to a function
  • methods=['GET', 'POST'] — accept form submissions too
  • /user/<id> — capture part of the URL as a value

Official documentation: Flask Documentation: Routing

Related lessons