django 跨域

  使用vue  axios报错

has been blocked by CORS policy: Response to preflight request doesn't pass access control check: No 'Access-Control-Allow-Origin' header

  django 添加中间件

附上代码:

from django.utils.deprecation import MiddlewareMixin
class AccessControl(MiddlewareMixin):

    def process_response(self, request, response):
        print(response)
        # response['Access-Control-Allow'] = '*'
        response['Access-Control-Allow-Headers'] = '*'
        response['Access-Control-Allow-Origin'] = '*'
        # response['Allow'] = 'GET, HEAD, OPTIONS, POST'
        print(response)
        return response

  

posted @ 2020-09-24 19:40  烟雨半生  阅读(241)  评论(0编辑  收藏  举报