在GenericAPIView的实现上添加自定义操作

时间:2019-04-02 23:13:51

标签: django django-rest-framework swagger

这是我的代码

class RegisterUsers(GenericAPIView):

    permission_classes = (permissions.AllowAny,)

    def get_serializer_class(self):
        if self.request.method == 'POST':
            return SignupSerializer
        return UPSignupSerializer

    def post(self, request, *args, **kwargs):
        serialized = SignupSerializer(data=request.data)
        if serialized.is_valid():
            serialized.create()

            tokens = MyTokenObtainPairSerializer(request.data).validate(request.data)
            return Response(tokens, status=status.HTTP_201_CREATED)
        else:
            return Response(SignupSerializer._errors, status=status.HTTP_400_BAD_REQUEST)

    def put(self, reqest, pk, *args, **kwargs):
        pass

    @action(detail=True, methods=['post'])
    def dosomsing(self, request, *args, **kwargs):
        pass

    @api_view
    def dosomsing2(self, request, pk=None):
        pass

'dosomsing'和'dosomsing2'在招摇中不可见。我如何添加操作到genericapiviews类?

0 个答案:

没有答案