标签:def custom rest col dict dia code res turn
from rest_framework.renderers import JSONRenderer class customrenderer(JSONRenderer): def render(self, data, accepted_media_type=None, renderer_context=None): if renderer_context: if isinstance(data,dict): msg=data.pop("msg",‘请求成功‘) code=data.pop("code",0) else: msg="请求成功" code=0 ret={ ‘msg‘:msg, ‘code‘:code, ‘date‘:data } return super().render(ret,accepted_media_type,renderer_context) else: return super().render(data,accepted_media_type,renderer_context)
标签:def custom rest col dict dia code res turn
原文地址:https://www.cnblogs.com/wutanghua/p/11286042.html