Custom Error Responses in Flask: Revisited

In an earlier post I wrote up a method of returning unimplemented status codes in Flask based on subclassing werkzeug.exceptions.HTTPException.

As it turns out, the output of Flask view functions are run through a liberal factory function that converts the return value into a response object. This makes it easy to output an otherwise unimplemented status code by returning a simple tuple from your view function.

This way there’s no need to subclass anything from Werkzeug.