美文网首页
Django Rest Framework取消csrf

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