from rest_framework.parsers import JSONParser from rest_framework.renderers import JSONRenderer class TextJSONRenderer(JSONRenderer): """支持 text/json 的响应渲染器""" media_type = 'text/json' # 覆盖默认值 format = 'json' # 保持默认格式 class TextJSONParser(JSONParser): """支持 text/json 的解析器""" media_type = 'text/json'