Last active
October 29, 2020 00:22
-
-
Save hussaintamboli/47f5245a5e0fe6c16735 to your computer and use it in GitHub Desktop.
Return a Custom response in flask restful API
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from flask import Response, jsonify | |
import json | |
from flask_restful import Resource | |
class Api(Resource): | |
def post(self): | |
response = Response( | |
response=json.dumps(dict(error='err')), | |
status=400, mimetype='application/json') | |
return response | |
# alternative | |
def get(self): | |
response = jsonify(dict(error='err')) | |
response.status_code = 400 | |
return response |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Very helpful (y)