rest_framework.response下的Response的二次封装

封装Response

from rest_framework.response import Response
class APIResponse(Response):
    def __init__(self, data_status, msg, results=None, headers=None, status=None, **kwargs):
        data = {
            'status': data_status,
            'msg': msg,
        }
        if results:
            data['results'] = results
        data.update(kwargs)
        super().__init__(data=data, headers=headers, status=status)

使用:APIResponse(0, 'ok', {}, headers, status)

猜你喜欢

转载自www.cnblogs.com/huanghongzheng/p/11369574.html
今日推荐