DRF 身份验证类装饰器不起作用

时间:2021-03-04 16:08:47

标签: django django-rest-framework

我遇到了一个问题,即 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 错误。怎么了?

1 个答案:

答案 0 :(得分:0)

问题出在装饰器顺序上。首先应该是 api_view