You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
28 lines
1.0 KiB
28 lines
1.0 KiB
from rest_framework.renderers import JSONRenderer |
|
|
|
|
|
class MyRenderers(JSONRenderer): |
|
def render(self, data, accepted_media_type=None, renderer_context=None): |
|
print(data) |
|
print(accepted_media_type) |
|
print(renderer_context) |
|
if renderer_context: |
|
if isinstance(data, dict): |
|
msg = data.pop('msg', '请求成功') |
|
code = data.pop('code', renderer_context['response'].status_code) |
|
next = data.pop('next', data['next']) |
|
if 'result' in data: |
|
data = data['result'] |
|
else: |
|
next = '' |
|
|
|
return_data = { |
|
'code': renderer_context['response'].status_code, |
|
'msg': renderer_context['response'].status_text, |
|
'next': next, |
|
'data': data, |
|
} |
|
return super().render(return_data, accepted_media_type, renderer_context) |
|
else: |
|
return super().render(data, accepted_media_type, renderer_context) |
|
|
|
|