You can use the 'permission_classes' attribute in the 'APIView' class to specify the permission classes for your view. To apply it only to the POST method, you can override the 'post' method and add the 'permission_classes' attribute there. Here's an example:

from rest_framework.views import APIView
from rest_framework.permissions import IsAuthenticated

class MyView(APIView):
    def get(self, request):
        # your code for GET method

    def post(self, request):
        # your code for POST method

    # apply permission_classes only to POST method
    post.permission_classes = [IsAuthenticated]

In this example, the 'IsAuthenticated' permission class will only be applied to the POST method, and not to the GET method.


原文地址: https://www.cveoy.top/t/topic/mlQM 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录