Django Rest Framework取消csrf
作者:
一只肥豚鼠 | 来源:发表于
2019-02-15 19:19 被阅读10次
首先写一个中间件
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)
类似于这样

image
本文标题:Django Rest Framework取消csrf
本文链接:https://www.haomeiwen.com/subject/mswmeqtx.html
网友评论