How Can I Disable Authentication in Django REST Framework

后端 未结 7 921
庸人自扰
庸人自扰 2020-12-13 23:11

I\'m working on a store site, where every user is going to be anonymous (well, until it\'s time to pay at least), and I\'m trying to use Django REST Framework to serve the p

7条回答
  •  隐瞒了意图╮
    2020-12-13 23:54

    You can also disable authentication for particular class or method, just keep blank the decorators for the particular method.

    from rest_framework.decorators import authentication_classes, permission_classes
    
    @api_view(['POST'])    
    @authentication_classes([])
    @permission_classes([])
    def items(request):
       return Response({"message":"Hello world!"})
    

提交回复
热议问题