Public Endpoint in Django Rest Framework

Disable Authentication in Django REST Framework for a single or multiple APIView classes.


Django Rest Framework packs with a bundle of handy permission and authentication classes to allot different permissions depending on day to day needs. But it lacks a permission to bypass the existing permission and go over without an authentication and make an open endpoint.

The is not a requirement in a typical application but I needed an open api endpoint to transfer status to a different application and all other views require authentication.

Django uses permission class to check if the user requesting has permission to the view. Permission classes uses authenticated data returned from authentication class (which authenticates user using credentials and then by session or Token) to run over the list of permissions and decided whether or not to allow the request to pass.

To make a view accessible to anonymous user you need to set the permission classes to null.

Class based view

class PublicEndpoint(APIView):

 permission_classes = []

 def get(self, request):
  return Response({'Public Endpoint'})

Functional View

from rest_framework.decorators import authentication_classes, permission_classes

def items(request):
   return Response({'Public Endpoint'})


Wow ! you have someting to tell us. That's great! Please keep in mind that comments are moderated, we employ rel="nofollow" for links, avoid using a spammy word or a domain in name field, it might end up as a Spam. Thanks for reading.

Last 5 Articles

All Articles >

  1. Mitigating Risks In Custom Software Development

  2. Container Security to Secure Microservices

  3. Strategic Messaging

  4. URL Shortener in Django

  5. MySQL as Database Option


News Letter

Subscribe to our email newsletter for useful tips and valuable resources, sent out every new article release.