首页 > 其他分享 >自定义跨域中间件

自定义跨域中间件

时间:2023-02-15 14:14:37浏览次数:34  
标签:Control Acess 跨域 自定义 中间件 Allow response

from django.utils.deprecation import MiddlewareMixin


class CorsMiddleware(MiddlewareMixin):
   """屏蔽CORS跨域"""

   def process_response(self, request, response):
       # 使用*表示所有的跨域请求都可以,这样会有风险
       response['Acess-Control-Allow-Origin'] = '*'
       if request.method == 'OPTIONS':
           response['Acess-Control-Allow-Credentials'] = 'true'
           response['Acess-Control-Allow-Header'] = 'content-type, X-Requested-With, X-CSRFToken'
           response['Acess-Control-Allow-Methods'] = 'GET,POST,PUT'
       return response

标签:Control,Acess,跨域,自定义,中间件,Allow,response
From: https://www.cnblogs.com/vonmo/p/17122574.html

相关文章