# utils/common_response.py
from rest_framework.response import Response
class APIResponse(Response):
def __init__(self, code=100, msg='成功', status=None, headers=None, **kwargs):
data = {'code': code, 'msg': msg}
# kwargs 有可能是 {token:asdfad,name:lqz}
if kwargs:
data.update(kwargs) #data字典 update k值重复,就会更新
# 调用父类(Response)的__init__完成初始化
super().__init__(data=data, status=status, headers=headers)
封装Response
于 2023-06-19 09:42:37 首次发布
![](https://img-home.csdnimg.cn/images/20240711042549.png)