首先写一个中间件
from rest_framework.authentication import SessionAuthentication, BasicAuthentication
class CsrfExemptSessionAuthentication(SessionAuthentication):
def enforce_csrf(self, request):
return # To not perform the csrf check previously happening
然后在setting中设置这个中间件
在每个类中添加一段代码
authentication_classes = (CsrfExemptSessionAuthentication, BasicAuthentication)
网友评论