← Flask tutorial

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.

Example
@app.route("/greet/<name>")
def greet(name):
    return f"Hello, {name}!"
Output
Visiting /greet/Ada returns: Hello, Ada!
Ready to go further?

These free tutorials are a preview, our Backend Development cohort covers it in depth, with a real project and a cohort alongside you. Active

Enroll in Backend Development
Don't miss out

Ready to build something real?

Create a free account to enroll in a track, and get notified the moment a cohort opens.

Create free account