Reputation: 425
I use django rest framework, example code
class TestApiView(APIView):
def get(self, request):
return Response({'text': 'allow any'})
def post(self, request):
return Response({'text': 'IsAuthenticated'})
how to make method GET accessible to all, and method POST only authorized
thank you in advance
Upvotes: 2
Views: 580
Reputation: 47364
You can use IsAuthenticatedOrReadOnly
permission class:
from rest_framework.permissions import IsAuthenticatedOrReadOnly
class TestApiView(APIView):
permission_classes = (IsAuthenticatedOrReadOnly,)
def get(self, request):
return Response({'text': 'allow any'})
def post(self, request):
return Response({'text': 'IsAuthenticated'})
Upvotes: 4