Complete the code to enable debug mode in a Flask app.
from flask import Flask app = Flask(__name__) app.run(debug=[1])
Setting debug=True enables debug mode in Flask, which shows detailed error pages.
Complete the code to define a route that triggers an error for testing debug pages.
@app.route('/error') def error(): return 1 / [1]
Dividing by zero (1 / 0) raises an error to test debug error pages.
Fix the error in the code to properly enable debug mode when running the Flask app.
if __name__ == '__main__': app.run([1]=True)
The correct parameter to enable debug mode in app.run() is debug.
Fill both blanks to create a custom error handler for 404 errors that shows a debug message.
@app.errorhandler([1]) def not_found(error): return "Error [2]: Page not found", 404
The error code for 'Not Found' is 404, so both blanks should be 404.
Fill all three blanks to log errors and show debug info when an exception occurs.
import logging @app.errorhandler([1]) def handle_exception(e): logging.[2](f"Error occurred: {e}") return "Debug info: " + str(e), [3]
Use Exception to catch all errors, logging.exception to log with traceback, and return HTTP status 500 for server errors.