1. from rest_framework.response import Response
    2. class APIResponse(Response):
    3. def __init__(self, code=100, msg='成功', status=None, headers=None,
    4. exception=False, content_type=None, **kwargs):
    5. real_data = {
    6. 'code': code,
    7. 'msg': msg,
    8. }
    9. if kwargs:
    10. real_data.update(kwargs)
    11. super().__init__(data=real_data, status=status, headers=headers,
    12. exception=exception, content_type=content_type)

    调用:

    1. # 首先导入
    2. return APIResponse()