Flask JSON Custom Error Page


is there any implementation exists on JSON as custom error page on Flask?

12/14/2011 10:51:23 AM

You can create a json response object using the "jsonify" helper from flask and then set the status_code of the response before returning it like this:

def not_found(error):
    response = jsonify({'code': 404,'message': 'No interface defined for URL'})
    response.status_code = 404
    return response

You can register this function as the handler by wrapping it in the errorhandler:

def not_found(error):

OR, setting it directly on the error_handler_spec:

app.error_handler_spec[None][404] = not_found
1/25/2012 12:56:05 AM

Licensed under: CC-BY-SA with attribution
Not affiliated with: Stack Overflow