一.关于中间建跨域
为了减少跨域代码冗余,采用中间件
from django.utils.deprecation import MiddlewareMixinclass CorsMiddleware(MiddlewareMixin): def process_response(self,request,response): # 复杂跨域 response["Access-Control-Allow-Headers"] = "*" # 简单跨域 response["Access-Control-Allow-Origin"] = "*" # put请求 需要的跨域 response["Access-Control-Allow-Methods"] = "*" return response