我遇到了一个问题,即 authentication_classes 装饰器不起作用。猜猜,我的代码肯定有错误
views.py
@authentication_classes([authentication.BaseAuthentication])
@permission_classes([permissions.IsAuthenticated])
@api_view(['GET'])
def profile(request):
# some logic
return Response()
urls.py
urlpatterns = [
path(r"profile/", profile, name='profile'),
]
当我在此端点上发送没有任何身份验证数据的请求时,我不会收到 401 错误。怎么了?
答案 0 :(得分:0)
问题出在装饰器顺序上。首先应该是 api_view