Reputation: 881
I am using django rest framework for authentication.
'DEFAULT_AUTHENTICATION_CLASSES': (
'rest_framework.authentication.SessionAuthentication',
'rest_framework.authentication.BasicAuthentication'
),
But in my register function:
class UserRegister(APIView):
@staticmethod
def post(request, user_name):
.
.
.
.
.
obviously I do not need token, however I am getting error:
"detail": "Authentication credentials were not provided."
I tried this possible answer: this answer
but I am encountering this error:
'staticmethod' object has no attribute '__name__'
and by deleting @staticmethod decorator, I am getting the previous error again:
"detail": "Authentication credentials were not provided."
How to exclude this special function from requiring token?
tnx
Upvotes: 0
Views: 1992
Reputation: 1397
this is the option for it
from rest_framework.permissions import AllowAny
class ViewName(APIView):
permission_classes = [AllowAny]
def get(self, request, format=None):
......
Try this....
Upvotes: 0
Reputation: 88619
I think this might work,
class UserRegister(APIView):
authentication_classes = []
def post(request, user_name):
# do your stuff
return Response()
Upvotes: 2
Reputation: 6040
If you want to disable authentication completely on any DRF view, you can override the permission_classes
field.
Your code should look something like :
class UserRegister(APIView):
permission_classes = []
def post():
Upvotes: 6