drf框架中的响应组件
02-05 响应组件
1.使用
from rest_framework.response import Response
class BookAPIView(APIView):
def get(self, request, *args, **kwargs):
return Response(data={...}, status=...,)
# 1.参数:Response(data=响应的数据, status=响应的网络状态码, headers=通过响应头携带数据给前端)
# 2.属性:response.data(数据), response.status_code(响应的状态码), response.status_text(响应的状态信息)
2.源码
class Response(SimpleTemplateResponse):
def __init__(self, data=None, status=None,
template_name=None, headers=None,
exception=False, content_type=None):
...
...
...