我正在使用django rest框架进行身份验证。
'DEFAULT_AUTHENTICATION_CLASSES': (
'rest_framework.authentication.SessionAuthentication',
'rest_framework.authentication.BasicAuthentication'
),
但在我的注册功能中:
class UserRegister(APIView):
@staticmethod
def post(request, user_name):
.
.
.
.
.
显然我不需要令牌,但是我收到了错误:
"detail": "Authentication credentials were not provided."
我尝试了这个可能的答案: this answer
但是我遇到了这个错误:
'staticmethod' object has no attribute '__name__'
并删除@staticmethod装饰器,我再次收到上一个错误:
"detail": "Authentication credentials were not provided."
如何从需要令牌中排除此特殊功能?
TNX
答案 0 :(得分:4)
如果要在任何DRF视图上完全禁用身份验证,可以覆盖permission_classes
字段。
您的代码应该类似于:
class UserRegister(APIView):
permission_classes = []
def post():
答案 1 :(得分:0)
这是它的选项
from rest_framework.permissions import AllowAny
class ViewName(APIView):
permission_classes = [AllowAny]
def get(self, request, format=None):
......
试试这个......