将模型对象转换为json字典:model_to_dict
作者:互联网
例子
from rest_framework.views import APIView
class StudentAPIView(APIView):
def get(self, request):
pk = request.query_params.get(pk)
student_obj = Student.objects.get(pk)
return Response(model_to_dict(student_obj))
# model_to_dict中的参数
model_to_dict(模型对象, fields(指定返回的字段), exclude(排除返回的字段))
标签:get,APIView,json,dict,student,pk,model 来源: https://www.cnblogs.com/weiweivip666/p/14628258.html