How django-rest-framework customizes json data structures

< H1 > how django-rest-framework customizes json data structures < / H1 > The json data structure returned by the

framework is data (a list), but I need to add the business response code to this data. The response information structure is as follows:

{
    "data": data,
    "code": code,
    "msg": msg
}

I have considered modifying the json structure in the middleware, but because the framework"s response class has a render state, it can only be rendered once, so I give up the middleware method and want to find a new method:)


if I understand correctly, the code you defined is the http status code.
then please see the following actions, otherwise please bypass ~

Don't talk too much nonsense, just go to the code:

from reset_framework.views import APIview
from reset_framework.reponse import Response

class test(APIView):
    def get(self, request):
    -sharp do somethings
    return Response(data="you want response data", status=200)

where the Django HttpResponse encapsulated by Response in rest_framework also provides the status http status code.
BTW, also provides template_name, headers, exception, content_type, data, status .
I hope it will be helpful to you

MySQL Query : SELECT * FROM `codeshelper`.`v9_news` WHERE status=99 AND catid='6' ORDER BY rand() LIMIT 5
MySQL Error : Disk full (/tmp/#sql-temptable-64f5-1b3673e-2b791.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
MySQL Errno : 1021
Message : Disk full (/tmp/#sql-temptable-64f5-1b3673e-2b791.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
Need Help?