Challenge - 5 Problems
Flask Route Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ component_behavior
intermediate2:00remaining
What is the output when accessing '/' route?
Given this Flask app code, what will the browser display when visiting the '/' URL?
Flask
from flask import Flask app = Flask(__name__) @app.route('/') def home(): return 'Welcome Home!' if __name__ == '__main__': app.run()
Attempts:
2 left
💡 Hint
Check what the @app.route('/') decorator does.
✗ Incorrect
The @app.route('/') decorator tells Flask to run the home() function when the root URL '/' is accessed. The function returns 'Welcome Home!' which is shown in the browser.
📝 Syntax
intermediate2:00remaining
Which option causes a syntax error in route definition?
Identify which route decorator syntax is invalid in Flask.
Attempts:
2 left
💡 Hint
Look for missing punctuation in the decorator.
✗ Incorrect
Option A is missing a comma between the URL string and the methods argument, causing a syntax error.
❓ state_output
advanced2:00remaining
What is the output of this Flask route with variable?
What will be the output when visiting '/user/Alice' in this Flask app?
Flask
from flask import Flask app = Flask(__name__) @app.route('/user/<name>') def user(name): return f'Hello, {name}!' if __name__ == '__main__': app.run()
Attempts:
2 left
💡 Hint
The part captures the URL segment as a function argument.
✗ Incorrect
The route captures 'Alice' as the name parameter and returns 'Hello, Alice!'.
🔧 Debug
advanced2:00remaining
Why does this Flask app raise a 404 error for '/hello'?
Given the code below, why does visiting '/hello' cause a 404 error?
Flask
from flask import Flask app = Flask(__name__) @app.route('/hello/') def greet_slash(): return 'Hi with slash!' if __name__ == '__main__': app.run()
Attempts:
2 left
💡 Hint
Check how Flask treats trailing slashes in routes.
✗ Incorrect
Flask treats '/hello' and '/hello/' as different routes. If only '/hello/' is defined, visiting '/hello' gives 404 unless redirect is enabled.
🧠 Conceptual
expert2:00remaining
Which option correctly explains Flask route matching behavior?
Choose the correct statement about how Flask matches URLs to route decorators.
Attempts:
2 left
💡 Hint
Think about how Flask treats trailing slashes and case sensitivity.
✗ Incorrect
Flask matches routes exactly including trailing slashes and is case-sensitive by default. It does not match prefixes automatically.