Created
August 23, 2016 16:30
-
-
Save wozozo/ec93a1d6d75bdeb18231dce6f83e1630 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
import json | |
from pyramid.renderers import JSON | |
class FlaskRenderer(JSON): | |
def __call__(self, info): | |
def _render(value, system): | |
request = system.get('request') | |
if request is not None: | |
response = request.response | |
ct = response.content_type | |
if ct == response.default_content_type: | |
response.content_type = 'application/json' | |
default = self._make_default(request) | |
# `value` = flask response | |
return self.serializer(json.loads(value.data.decode('utf8')), default=default, **self.kw) | |
return _render | |
config.add_renderer('flask', FlaskRenderer()) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment