Challenge - 5 Problems
Flask Request Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ component_behavior
intermediate2:00remaining
What does this Flask route return?
Consider this Flask app code. What is the output when you visit
/hello in a browser?Flask
from flask import Flask app = Flask(__name__) @app.route('/hello') def hello(): return 'Hello, Flask!' if __name__ == '__main__': app.run()
Attempts:
2 left
💡 Hint
Check the route decorator and the return value of the function.
✗ Incorrect
The route decorator @app.route('/hello') connects the URL path '/hello' to the hello() function. When you visit '/hello', Flask calls hello() and returns its string, which the browser displays.
❓ state_output
intermediate2:00remaining
What is the value of
request.method inside this route?Given this Flask route, what will
request.method be if you send a POST request to /submit?Flask
from flask import Flask, request app = Flask(__name__) @app.route('/submit', methods=['GET', 'POST']) def submit(): return f'Method used: {request.method}' if __name__ == '__main__': app.run()
Attempts:
2 left
💡 Hint
Look at the HTTP method used in the request and the allowed methods in the route.
✗ Incorrect
The route allows GET and POST. If you send a POST request, request.method will be 'POST'.
📝 Syntax
advanced2:30remaining
Which option correctly defines a Flask route that accepts a dynamic integer parameter?
You want a route that matches URLs like
/user/42 where 42 is a number. Which code snippet correctly defines this route?Attempts:
2 left
💡 Hint
Flask uses syntax for dynamic parts in routes.
✗ Incorrect
Flask route parameters use syntax. means convert the URL part to int and assign to id.
🔧 Debug
advanced2:30remaining
Why does this Flask app raise a RuntimeError?
This Flask app code raises a RuntimeError: Working outside of application context. Why?
Flask
from flask import Flask, current_app app = Flask(__name__) print(current_app.name) if __name__ == '__main__': app.run()
Attempts:
2 left
💡 Hint
current_app needs an active application context to work.
✗ Incorrect
current_app only works inside an application context, which Flask creates during requests or when pushed manually. Accessing it at the top level causes RuntimeError.
🧠 Conceptual
expert3:00remaining
What is the correct order Flask processes an incoming HTTP request?
Arrange these steps in the order Flask processes an HTTP request internally.
Attempts:
2 left
💡 Hint
Flask needs a context before matching routes and running code.
✗ Incorrect
Flask first creates a request context, then matches the URL to a route, runs the route function, then sends the response.