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?
Consider a Flask app started with debug mode enabled. What is the main behavior you will observe during development?
Flask
from flask import Flask app = Flask(__name__) @app.route('/') def home(): return 'Hello, Flask!' if __name__ == '__main__': app.run(debug=True)
Attempts:
2 left
💡 Hint
Think about what debug mode helps developers do easily.
✗ Incorrect
Debug mode in Flask enables the interactive debugger and automatic reloads when code changes, making development faster and easier.
📝 Syntax
intermediate1:30remaining
Which code correctly enables debug mode in Flask?
Select the code snippet that correctly starts a Flask app with debug mode enabled.
Attempts:
2 left
💡 Hint
Debug expects a boolean value, not a string.
✗ Incorrect
The debug parameter expects a boolean True or False. Passing a string or integer may not work as intended.
🔧 Debug
advanced2:30remaining
What error occurs if you run Flask with debug=True but forget to set __name__ == '__main__'?
Given this code snippet, what error or behavior will occur?
from flask import Flask
app = Flask(__name__)
@app.route('/')
def home():
return 'Hi'
app.run(debug=True)
Flask
from flask import Flask app = Flask(__name__) @app.route('/') def home(): return 'Hi' app.run(debug=True)
Attempts:
2 left
💡 Hint
Think about how Flask's reloader works when not protected by the main guard.
✗ Incorrect
Without the if __name__ == '__main__' guard, the app.run(debug=True) causes the reloader to spawn a child process, running the code twice.
❓ state_output
advanced2:00remaining
What is the output when Flask debug mode triggers an error in a route?
If a route function raises an exception while Flask is running with debug=True, what will the user see in the browser?
Flask
from flask import Flask app = Flask(__name__) @app.route('/') def home(): raise ValueError('Oops!') if __name__ == '__main__': app.run(debug=True)
Attempts:
2 left
💡 Hint
Debug mode helps developers see what went wrong directly in the browser.
✗ Incorrect
With debug=True, Flask shows an interactive debugger with error details and stack trace in the browser when exceptions occur.
🧠 Conceptual
expert3:00remaining
Why should Flask debug mode never be enabled in production?
Select the best reason why running Flask with debug=True is unsafe in a production environment.
Attempts:
2 left
💡 Hint
Think about what the interactive debugger allows a user to do.
✗ Incorrect
The interactive debugger allows code execution from the browser, which is a major security risk if exposed publicly.