欢迎来到Cecilia陈的博客

孤独,是人一生最好的修行。

22 响应模块配置

二次封装Response模块

utils/response.py
from rest_framework.response import Response

class APIResponse(Response):
    def __init__(self, data_status=0, data_msg='ok', results=None, http_status=None, headers=None, exception=False, **kwargs):
        data = {
            'status': data_status,
            'msg': data_msg,
        }
        if results is not None:
            data['results'] = results
        data.update(kwargs)

        super().__init__(data=data, status=http_status, headers=headers, exception=exception)
posted @ 2019-12-03 21:37  Cecilia陈  阅读(102)  评论(0编辑  收藏  举报