Flask
Routes & View Functions
@app.route(path) above a function turns it into a
view — whatever it returns becomes the response body.
Example: capturing part of the URL
@app.route("/greet/")
def greet(name):
return f"Hello, {name}!"
Visiting /greet/Ada returns: Hello, Ada!
<name> inside the path captures that segment of the
URL and passes it straight into the function as an argument named
name — the same underlying idea as Next.js's
[slug] dynamic routes or Laravel's route parameters, just
Flask's specific syntax for it.
@app.route("/greet/<name>")
def greet(name):
return f"Hello, {name}!"
Visiting /greet/Ada returns: Hello, Ada!