后端跨域配置 安装 django-cors-headers 包 pip install django-cors-headers 设置INSTALL_APPS INSTALLED_APPS = [ ... 'corsheaders', ... ] 设置中间件 MIDDLEWARE = [ 'corsheaders.middleware.CorsMiddleware', ... ] 设置跨域白名单 # CORS跨域请求白名单设置 CORS_ORIGIN_WHITELIST = ( 'http://127.0.0.1:8080', 'http://localhost:8080' )