Permissions with IsAuthenticated

A snippet showing how to use IsAuthenticated permission class.


# views.py

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

class PrivateProfile(APIView):
    permission_classes = [IsAuthenticated]

    def get(self, request):
        return Response({"email": request.user.email})
      
Explanation:
  • Only authenticated requests (via configured auth classes) can access the endpoint.
Never miss a story on Django.wiki

Subscribe for fresh tutorials, snippets, and updates.

By subscribing you agree to our Privacy Policy.