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
}
{
"data": data,
"code": code,
"msg": msg
}
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
Previous: Django running py file reported an error
Next: Legend component in highcharts A weird bug about mobile
after getting the uploaded file, write the uploaded file stream to the server file. The file contains more http stream related information --X-INSOMNIA-BOUNDARY Content-Disposition: form-data; name="file"; filename="a.txt" Content...
class products (models.Model): MODE_CHOICES=(( week , ),( day , )) productname=models.CharField(max_length=30,unique=True) dutymode=models.CharField(max_length=30,choices=MODE_CHOICES,default= week ) class dutygroups (models.Model): pro...
an interface: http: 127.0.0.1:8000 api v1 course corresponds to the following processing view class CourseView(APIView): -sharp renderer_classes = [JSONRenderer,] def get(self, request, *args, **kwargs): ret = {"code": 1} ...
problem description there are a lot of TypeEroor errors, which feels like an error in front-end vue rendering, but I am a vue rookie and don t know how to handle it. the environmental background of the problems and what methods you have tried the...