drf自带的Response在实际项目中会代码重复严重,所以需要二次封装Response
from rest_framework.response import Response
class APIResponse(Response):
def __init__(self,code=100,msg='成功',data=None,headers=None,**kwargs):
dic ={'code':code,'msg':msg}
if data:
dic ={'code':code,'msg':msg,'data':data}
dic.update(kwargs)
super.__init__(data=dic, status=status,headers=headers,)