我认为DRF中默认所有POST, PUT, DELETE个请求都受到CSRF保护,但我在一些教程视频中看到,他们在大约class-based个视图中使用@method_decorator(csrf_protect)
来执行Post和RST请求,所以我也这样做了.
但现在我在想,当这些请求默认受CSRF保护时,这样做的目的是什么?
@method_decorator(csrf_protect, name='dispatch')
class LogoutView(APIView):
def post(self, request, format=None):
try:
auth.logout(request)
return Response({'success': 'Logged out.'})
except Exception as e:
print(e)
return Response({'error': 'Something went wrong.'})