考虑到我有一个简单的观点,
# serializers.py
class EmptyPayloadResponseSerializer(serializers.Serializer):
detail = serializers.CharField()
# views.py
from rest_framework.views import APIView
from rest_framework.response import Response
from drf_spectacular.utils import extend_schema
from .serializers import EmptyPayloadResponseSerializer
class EmptyPayloadAPI(APIView):
@extend_schema(responses=EmptyPayloadResponseSerializer)
def post(self, request, *args, **kwargs):
# some actions
return Response(data={"detail": "Success"})
当我渲染架构时,我得到了以下错误响应,
错误 #0:EmptyPayloadAPI:无法猜测序列化程序。这是对 APIViews 的优雅回退处理。如果视图在您的控制之下,请考虑使用 GenericAPIView 作为视图基类。暂时忽略视图。
那么,我如何告诉@extend_schema
装饰器我不打算将任何内容作为有效负载传递?