Response封装
class APIResponse(Response):
def __init__(self,code=100,msg='成功',data=None,status=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)
使用
# 就可以随便传你自定义的参数
return APIResponse(data={"name":'tiger'},token='asaadddaa',aa='qweqweqwe')
return APIResponse(data={"name":'tiger'})
return APIResponse(code='101',msg='错误',data={"name":'tiger'},token='asaadddaa',aa='qweqweqwe',header={})
标签:code,封装,APIResponse,dic,msg,data,Response
From: https://www.cnblogs.com/piggthird/p/17804256.html