Challenge - 5 Problems
Flask Route Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
🧠 Conceptual
intermediate2:00remaining
Understanding Flask route naming conventions
Which of the following route names follows the best Flask naming convention for a URL that shows a user's profile page?
Attempts:
2 left
💡 Hint
Think about readability and common URL patterns using hyphens or underscores.
✗ Incorrect
Flask route names typically use lowercase letters and hyphens to separate words for readability and SEO benefits. So /user-profile is preferred.
❓ component_behavior
intermediate2:00remaining
Route behavior with trailing slashes
Given a Flask route defined as
@app.route('/dashboard/'), what happens when a user visits /dashboard (without the trailing slash)?Attempts:
2 left
💡 Hint
Think about how Flask handles routes with trailing slashes and user requests without them.
✗ Incorrect
Flask automatically redirects requests missing a trailing slash to the route with the slash if the route is defined with a trailing slash.
📝 Syntax
advanced2:00remaining
Correct route parameter syntax in Flask
Which of the following route definitions correctly captures an integer user ID in Flask?
Flask
@app.route(...)
Attempts:
2 left
💡 Hint
Flask uses a specific syntax for typed route parameters.
✗ Incorrect
Flask uses <type:variable_name> syntax. The correct type for integers is int, so /user/<int:user_id> is correct.
🔧 Debug
advanced2:00remaining
Debugging route conflicts in Flask
Consider these two Flask routes:
What problem will occur when a user visits
@app.route('/item/') @app.route('/item/new')What problem will occur when a user visits
/item/new?Attempts:
2 left
💡 Hint
Think about how Flask matches routes in order and how variable routes capture strings.
✗ Incorrect
The route with the variable <id> will match any string, including 'new', so the static route /item/new will never be matched.
❓ lifecycle
expert3:00remaining
Order of route matching in Flask
Given these Flask routes:
1.
2.
3.
In what order does Flask check these routes when a user visits
1.
@app.route('/post/') 2.
@app.route('/post/archive')3.
@app.route('/post/') In what order does Flask check these routes when a user visits
/post/archive?Attempts:
2 left
💡 Hint
Flask matches routes in the order they are defined in the code.
✗ Incorrect
Flask checks routes in the order they are declared. So if the integer parameter route is declared first, it tries that before the static route.