from django.utils.deprecation import MiddlewareMixin标签:Control,Acess,跨域,自定义,中间件,Allow,response From: https://www.cnblogs.com/vonmo/p/17122574.html
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