我'm working on a Django Web API that'应该服务于一个单独的Angular 5客户端 . Django应用程序在localhost:49846上运行,Angular在localhost上运行:50887,所以我需要启用CORS . 我尝试使用django-cors-headers . 我已经安装了包并将以下行添加到我的 settings.py 文件中:

INSTALLED_APPS = [
   ...
   'corsheaders',
   ...
]

MIDDLEWARE_CLASSES = [
   'corsheaders.middleware.CorsMiddleware',
   ...
]

CORS_ORIGIN_ALLOW_ALL = True

但是当客户端发出请求时,我仍然会收到以下错误:

对预检请求的响应未通过访问控制检查:请求的资源上不存在“Access-> Control-Allow-Origin”标头 . 原因>'http:// localhost:50887'因此不允许访问 .

目前我正在使用Allow-Control-Allow-Origin: * Chrome扩展程序,一切正常,但我想找到一种从我的API处理CORS问题的方法 .