Skip to content

Instantly share code, notes, and snippets.

@hussaintamboli
Last active October 29, 2020 00:22
Show Gist options
  • Save hussaintamboli/47f5245a5e0fe6c16735 to your computer and use it in GitHub Desktop.
Save hussaintamboli/47f5245a5e0fe6c16735 to your computer and use it in GitHub Desktop.
Return a Custom response in flask restful API
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
@anandtripathi5
Copy link

Very helpful (y)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment