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
- Capture Variables from the Path
- Type Converters: int, float, string, path
- Build URLs with url_for
- Trailing Slashes and Redirect Behavior