Last active
July 2, 2018 15:14
-
-
Save jerinisready/d2689745e6d76318393b2e3f2399a446 to your computer and use it in GitHub Desktop.
A Quick Login Required Mixin For Django Rest Framework
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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