0
0
Flaskframework~10 mins

Debug mode error pages in Flask - Interactive Code Practice

Choose your learning style9 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete the code to enable debug mode in a Flask app.

Flask
from flask import Flask
app = Flask(__name__)
app.run(debug=[1])
Drag options to blanks, or click blank then click option'
A1
BTrue
C"yes"
DFalse
Attempts:
3 left
💡 Hint
Common Mistakes
Using a string like "yes" instead of a boolean True.
Setting debug to False disables debug mode.
2fill in blank
medium

Complete the code to define a route that triggers an error for testing debug pages.

Flask
@app.route('/error')
def error():
    return 1 / [1]
Drag options to blanks, or click blank then click option'
ANone
B"0"
C1
D0
Attempts:
3 left
💡 Hint
Common Mistakes
Using 1 or None which do not cause errors.
Using a string "0" which causes a different error.
3fill in blank
hard

Fix the error in the code to properly enable debug mode when running the Flask app.

Flask
if __name__ == '__main__':
    app.run([1]=True)
Drag options to blanks, or click blank then click option'
Adebug
Bdebug_mode
Crun_debug
Dmode_debug
Attempts:
3 left
💡 Hint
Common Mistakes
Using incorrect parameter names like debug_mode or run_debug.
Forgetting to set debug to True.
4fill in blank
hard

Fill both blanks to create a custom error handler for 404 errors that shows a debug message.

Flask
@app.errorhandler([1])
def not_found(error):
    return "Error [2]: Page not found", 404
Drag options to blanks, or click blank then click option'
A404
B500
C403
D400
Attempts:
3 left
💡 Hint
Common Mistakes
Using other error codes like 500 or 403 which mean different errors.
Mismatching error codes in decorator and return statement.
5fill in blank
hard

Fill all three blanks to log errors and show debug info when an exception occurs.

Flask
import logging

@app.errorhandler([1])
def handle_exception(e):
    logging.[2](f"Error occurred: {e}")
    return "Debug info: " + str(e), [3]
Drag options to blanks, or click blank then click option'
AException
Berror
C500
Dexception
Attempts:
3 left
💡 Hint
Common Mistakes
Using lowercase 'exception' as the error type instead of Exception.
Using logging.error instead of logging.exception for full traceback.
Returning wrong HTTP status codes.