The DebuggedApplication()
middleware only works if an uncaught exception reaches it.
Flask, in production mode, catches all exceptions so these never reach the middleware.
You need to explicitly tell Flask to not catch all exceptions with:
PROPAGATE_EXCEPTIONS = True
in your configuration. From the relevant documenation:
PROPAGATE_EXCEPTIONS
Exceptions are re-raised rather than being handled by the app’s error handlers. If not set, this is implicitly true if TESTING
or DEBUG
is enabled.
You can set it on the app
object before wrapping it in the DebuggedApplication
middleware:
app = Flask(__name__)
app.config['PROPAGATE_EXCEPTIONS'] = True
app.wsgi_app = DebuggedApplication(app.wsgi_app, True)
Note that this only tells Flask to not catch all exceptions any more. You may also want to set other configuration options such as PRESERVE_CONTEXT_ON_EXCEPTION
, or you could just enable debug mode with app.debug = True
.