Recall & Review
beginner
What is a dynamic parameter in a Flask route?
A dynamic parameter is a part of the URL that can change and is captured by the route to pass as a variable to the view function. It allows routes to handle different inputs without defining multiple static routes.
Click to reveal answer
beginner
How do you define a route with a dynamic parameter in Flask?
Use angle brackets in the route URL, like <parameter_name>. For example, @app.route('/user/<username>') captures the username from the URL and passes it to the function.
Click to reveal answer
intermediate
What data types can you specify for dynamic parameters in Flask routes?
You can specify types like , , or . This helps Flask convert the URL part to the correct Python type before passing it to the function.
Click to reveal answer
intermediate
What happens if a dynamic parameter does not match the specified type in Flask?
Flask will return a 404 Not Found error because the URL does not match the route pattern with the expected type.
Click to reveal answer
beginner
Show a simple Flask route example with a dynamic parameter and explain its behavior.
Example:
@app.route('/post/')
def show_post(post_id):
return f"Post {post_id}"
This route captures an integer post_id from the URL and returns a string showing that post's ID.
Click to reveal answer
How do you capture a username from the URL in a Flask route?
✗ Incorrect
Flask uses angle brackets < > to capture dynamic parameters in routes.
What type will Flask convert the parameter to if you use in the route?
✗ Incorrect
The syntax tells Flask to convert the URL part to an integer.
What response does Flask give if the URL parameter does not match the expected type?
✗ Incorrect
Flask returns a 404 Not Found if the URL does not match the route pattern.
Which of these is a valid dynamic parameter for a file path in Flask?
✗ Incorrect
The converter captures a path including slashes.
What is the purpose of dynamic parameters in Flask routes?
✗ Incorrect
Dynamic parameters let routes accept variable parts of the URL and pass them to the function.
Explain how to create a Flask route that accepts a dynamic username and returns a greeting message.
Think about how to capture and use the username from the URL.
You got /3 concepts.
Describe the role of type converters in Flask dynamic routes and give examples.
Consider why you might want to ensure a parameter is an integer.
You got /3 concepts.