Loading

解决前后端跨域问题

1.代码

img
from django.utils.deprecation import MiddlewareMixin

class CoresMiddleware(MiddlewareMixin):
    def process_response(self, request, response):
        response['Access-Control-Allow-Origin'] = "*"
        response['Access-Control-Allow-Headers'] = "*"
        response['Access-Control-Allow-Methods'] = "*"
        return response

2.注册中间件

img

注意:
请求头不支持带下划线,要用驼峰;
跨域中间件要放首位(可以试一下)

posted @ 2024-09-06 13:17  一只大学生  阅读(1)  评论(0编辑  收藏  举报