首先需要定义一个中间件
from django.utils.deprecation import MiddlewareMixin class CorsMiddleware(MiddlewareMixin): def process_response(self,request,response): response["Access-Control-Allow-Headers"] = "Content-Type" #get请求 response["Access-Control-Allow-Origin"]="http://localhost:8081" #post请求 return response
还需要在setting中的MIDDLEWARE中注册中间件
"api.utils.middleware.CorsMiddleware"
原文地址:https://www.cnblogs.com/qq631243523/p/10139675.html
时间: 2024-11-02 16:56:34