Challenge - 5 Problems
Flask Debug Mode Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ component_behavior
intermediate2:00remaining
What happens when Flask debug mode is enabled and an error occurs?
Consider a Flask app running with debug mode enabled. What will the user see if the app raises an unhandled exception during a request?
Flask
from flask import Flask app = Flask(__name__) app.debug = True @app.route('/') def index(): raise ValueError('Oops!') if __name__ == '__main__': app.run()
Attempts:
2 left
💡 Hint
Debug mode shows detailed error information to help developers fix bugs.
✗ Incorrect
When Flask debug mode is enabled, it shows a detailed interactive error page with the full traceback and a console to run Python code. This helps developers diagnose issues quickly.
📝 Syntax
intermediate2:00remaining
Which code snippet correctly enables debug mode in Flask?
You want to enable debug mode in your Flask app to see detailed error pages during development. Which of the following code snippets correctly enables debug mode?
Attempts:
2 left
💡 Hint
The debug parameter in app.run controls debug mode.
✗ Incorrect
Passing debug=True to app.run enables debug mode and shows detailed error pages. Setting app.debug = True alone does not always enable debug mode unless app.run is called accordingly.
🔧 Debug
advanced2:00remaining
What error occurs if you try to enable debug mode in production with Flask's built-in server?
You accidentally run your Flask app with debug=True on a public server. What error or warning will Flask show or raise?
Flask
from flask import Flask app = Flask(__name__) @app.route('/') def index(): return 'Hello' if __name__ == '__main__': app.run(debug=True, host='0.0.0.0')
Attempts:
2 left
💡 Hint
Flask protects the interactive debugger from remote access with a PIN.
✗ Incorrect
When debug mode is enabled and the app is accessible remotely, Flask requires a PIN to access the debugger to prevent unauthorized access. It raises a RuntimeError if the PIN is not provided.
❓ state_output
advanced2:00remaining
What is the output when Flask debug mode is disabled and an error occurs?
Given this Flask app with debug mode off, what will the user see if an unhandled exception is raised?
Flask
from flask import Flask app = Flask(__name__) app.debug = False @app.route('/') def index(): raise Exception('Error!') if __name__ == '__main__': app.run()
Attempts:
2 left
💡 Hint
Without debug mode, Flask hides error details from users.
✗ Incorrect
When debug mode is off, Flask shows a generic 500 error page without any traceback or debugging info to protect sensitive details.
🧠 Conceptual
expert2:00remaining
Why is it unsafe to run Flask with debug mode enabled on a public server?
Select the best explanation for why Flask's debug mode should never be enabled on a public-facing server.
Attempts:
2 left
💡 Hint
Think about what the interactive debugger can do if accessed by attackers.
✗ Incorrect
Flask's debug mode includes an interactive debugger that can execute arbitrary Python code. If exposed publicly, attackers can run harmful commands on the server.