0
0
Flaskframework~20 mins

Route decorator (@app.route) in Flask - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Flask Route Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
component_behavior
intermediate
2: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()
AThe browser shows a 404 Not Found error
BThe browser shows the text: Welcome Home!
CThe browser shows a 500 Internal Server Error
DThe browser shows a blank page
Attempts:
2 left
💡 Hint
Check what the @app.route('/') decorator does.
📝 Syntax
intermediate
2:00remaining
Which option causes a syntax error in route definition?
Identify which route decorator syntax is invalid in Flask.
A@app.route('/profile' methods=['GET'])
B@app.route('/contact', methods=['GET', 'POST'])
C@app.route('/about')
D@app.route('/login', methods=['POST'])
Attempts:
2 left
💡 Hint
Look for missing punctuation in the decorator.
state_output
advanced
2: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()
AHello, user!
BHello, <name>!
CHello, Alice!
D404 Not Found error
Attempts:
2 left
💡 Hint
The part captures the URL segment as a function argument.
🔧 Debug
advanced
2: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()
ABecause '/hello' and '/hello/' are treated as different routes in Flask
BBecause the greet() function has no return statement
CBecause Flask requires routes to be decorated with @app.get() instead of @app.route()
DBecause the app.run() is missing debug=True
Attempts:
2 left
💡 Hint
Check how Flask treats trailing slashes in routes.
🧠 Conceptual
expert
2:00remaining
Which option correctly explains Flask route matching behavior?
Choose the correct statement about how Flask matches URLs to route decorators.
AFlask ignores the order of route definitions when matching URLs
BFlask automatically matches any URL starting with the route prefix regardless of trailing slashes
CFlask matches routes case-insensitively by default
DFlask matches routes exactly and does not consider trailing slashes unless configured otherwise
Attempts:
2 left
💡 Hint
Think about how Flask treats trailing slashes and case sensitivity.