Skip to content

Instantly share code, notes, and snippets.

@jerinisready
Last active July 2, 2018 15:14
Show Gist options
  • Save jerinisready/d2689745e6d76318393b2e3f2399a446 to your computer and use it in GitHub Desktop.
Save jerinisready/d2689745e6d76318393b2e3f2399a446 to your computer and use it in GitHub Desktop.
A Quick Login Required Mixin For Django Rest Framework
from rest_framework.response import Response
import rest_framework.views
class APIView(rest_framework.views.APIView):
""" A Quick Login Required Mixin For Django Rest Framework """
def dispatch(self, request, *args, **kwargs):
if not request.user.is_authenticated():
return Response({'error': 'Please Authenticate to continue'}, status=405)
return super(self.__class__, self).dispatch(request, *args, **kwargs)
class MyDRFView(APIView):
pass
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment