drf自带的Response在实际项目中会代码重复严重,所以需要二次封装Response

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