重写Response
在utils文件下面新建response文件
from rest_framework.response import Response
class APIResponse(Response):
def __init__(self, status=100, msg='成功', http_status=None, template_name=None, headers=None, exception=False,
content_type=None, **kwargs):
data = {
'status': status,
'msg': msg
}
if kwargs:
data.update(kwargs)
super().__init__(data=data, status=http_status, template_name=template_name, headers=headers,
exception=exception, content_type=content_type)