Recall & Review
beginner
What is a teardown hook in Flask?
A teardown hook in Flask is a function that runs after each request, used to clean up resources like closing database connections.
Click to reveal answer
beginner
How do you register a teardown hook in Flask?
You register a teardown hook using the @app.teardown_appcontext decorator for app-level cleanup or @app.teardown_request for request-level cleanup.
Click to reveal answer
intermediate
When exactly does a teardown hook run in Flask?
A teardown hook runs after the response is sent to the client, regardless of whether the request was successful or raised an error.
Click to reveal answer
intermediate
What argument does a teardown function receive in Flask?
A teardown function receives an error argument that is None if no error occurred, or contains the exception if one happened during the request.
Click to reveal answer
beginner
Why are teardown hooks important in Flask applications?
Teardown hooks help prevent resource leaks by ensuring things like database connections or files are properly closed after each request.
Click to reveal answer
Which decorator is used to register a teardown hook for the entire Flask application context?
✗ Incorrect
The @app.teardown_appcontext decorator registers a function to run when the application context tears down.
When does a teardown hook run in Flask?
✗ Incorrect
Teardown hooks run after the response is sent, regardless of success or error.
What argument does a teardown function receive?
✗ Incorrect
Teardown functions receive an error argument that is None if no error occurred.
Which of these is a common use for teardown hooks?
✗ Incorrect
Teardown hooks are commonly used to close database connections or clean up resources.
Can teardown hooks modify the response sent to the client?
✗ Incorrect
Teardown hooks run after the response is sent, so they cannot modify it.
Explain what a teardown hook is in Flask and why it is useful.
Think about what happens after a web request finishes.
You got /4 concepts.
Describe how to register a teardown hook in Flask and what argument the function receives.
Focus on the decorator and function signature.
You got /3 concepts.