二次封装Response

from rest_framework.response import Response


# 二次封装Response
class APIResponse(Response):
    def __init__(self, http_status=0, msg='ok', results=None, status=None,
                 template_name=None, headers=None,
                 exception=False, content_type=None, **kwargs):
        data = {
            'status': http_status,
            'msg': msg,
        }
        if results is not None:
            data['result'] = results
        data.update(**kwargs)
        super().__init__(data=data, status=status,
                         template_name=template_name, headers=headers,
                         exception=exception, content_type=content_type)

posted @ 2019-11-25 20:40  cheerxiong  阅读(327)  评论(0编辑  收藏  举报