0PricingLogin
Flask Academy · Lesson

Capture Variables from the Path

Use angle-bracket parameters in routes.

Static Routes Hit a Wall

A fixed path like /user/alice only works for one person. To serve any name, you need a route that captures part of the URL as data.

Angle Brackets Capture Values

Wrap a path segment in angle brackets to turn it into a variable. Flask grabs whatever the user types there and hands it to your view as a parameter. 🎯

@app.route('/user/<name>')
def profile(name):
    return f'Hello, {name}!'

All lessons in this course

  1. Capture Variables from the Path
  2. Type Converters: int, float, string, path
  3. Build URLs with url_for
  4. Trailing Slashes and Redirect Behavior
← Back to Flask Academy