flask abort as json
from flask import abort, make_response, jsonify | |
abort(make_response(jsonify(message="Message goes here"), 400)) |
This comment has been minimized.
This comment has been minimized.
Also you could do just abort(jsonify(message="Message goes here")) |
This comment has been minimized.
This comment has been minimized.
WWWWWWWWWWWWWWWWWWWWWOW |
This comment has been minimized.
This comment has been minimized.
@hirobert, Why do we need abort here? Can we just write return instead of abort? |
This comment has been minimized.
This comment has been minimized.
<3 |
This comment has been minimized.
This comment has been minimized.
This is it |
This comment has been minimized.
This comment has been minimized.
@tamirOK in decorators you want to raise errors in some cases and not to return |
This comment has been minimized.
This comment has been minimized.
Notice that abort(jsonify(message="Message goes here")) returns |
This comment has been minimized.
This comment has been minimized.
THANK YOU THIS SAVED MY LIFE. I was sooo frustrated. My solution is this: abort(make_response(jsonify(errors=['Your input sucks', 'our service is down', 'Google is being slow suck it']), status, HEADERS)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This comment has been minimized.
From the docs, it wasn't obvious that
flask.abort
accepted also aflask.Response
, very helpful, thx!