Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
A snippet from the Kinja data team's implementation of make_response in our subclass of Flask
# In the default handler for flask, they don't allow None. We however
# allow anything that's json serializable. :)
if not isinstance(rv, self.response_class):
if isinstance(rv, (bytes, bytearray)):
# For now, treat bytes as raw data and don't attempt to
# JSON-serialize
rv = self.response_class(rv, status=status, headers=headers)
status = headers = None
# Try to coerce things that are Responses or wsgi callables already
elif isinstance(rv, WerkzeugResponse) or callable(rv):
rv = self.response_class.force_type(rv, request.environ)
# If this is gonna be a problem we'll soon find out!
rv = success(rv)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.