renderers.py 文件源码

python
阅读 23 收藏 0 点赞 0 评论 0

项目:django-realworld-example-app 作者: gothinkster 项目源码 文件源码
def render(self, data, media_type=None, renderer_context=None):
        if data.get('results', None) is not None:
            return json.dumps({
                self.pagination_object_label: data['results'],
                self.pagination_count_label: data['count']
            })

        # If the view throws an error (such as the user can't be authenticated
        # or something similar), `data` will contain an `errors` key. We want
        # the default JSONRenderer to handle rendering errors, so we need to
        # check for this case.
        elif data.get('errors', None) is not None:
            return super(ConduitJSONRenderer, self).render(data)

        else:
            return json.dumps({
                self.object_label: data
            })
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号