自定义中间件
在utils的cors下配置
from django.utils.deprecation import MiddlewareMixin
class CorsMiddleware(MiddlewareMixin):
def process_response(self, request, response):
response['Access-Control-Allow-Origin'] = '*'
response['Access-Control-Allow-Headers'] = '*'
response['Access-Control-Allow-Methods'] = '*'
return response
在settings的中间件配置路径
MIDDLEWARE = [
...
...
"utils.cors.CorsMiddleware"
]
最后跨域解决: