class MiddlewareMixin(object): def __init__(self, get_response=None): self.get_response = get_response super(MiddlewareMixin, self).__init__() def __call__(self, request): response = None if hasattr(self, 'process_request'): response = self.process_request(request) if not response: response = self.get_response(request) ifhasattr (Self, ' process_response ' ): the Response = self.process_response (Request, the Response) return the Response class CORSMiddleware (MiddlewareMixin): DEF process_response (Self, Request, the Response): # add response headers # allows your domain name to get my data Response [ ' Access-Control-the allow-Origin ' ] = " * " # allows you to carry the request header Content-Type Response [ ' Access-Control-the allow-Headers ' ] = " Content-Type " # 允许你发送DELETE,PUT response['Access-Control-Allow-Methods'] = "DELETE,PUT" return response
Add middleware settings.py file
Before and after the end of the separation development