我有一个本地Django设置如下
Django Rest Framework
:localhost:8000
AngularJS frontend
:local apache running on http://localservername
我安装了django-cors-headers
,在我的settings.py
,我设置了我的
CORS_ORIGIN_WHITELIST = ( 'http://localhost', 'localservername', 'http://localservername', '127.0.0.1' ) MIDDLEWARE_CLASSES = ( 'django.contrib.sessions.middleware.SessionMiddleware', 'corsheaders.middleware.CorsMiddleware', 'django.middleware.common.CommonMiddleware', 'django.middleware.csrf.CsrfViewMiddleware', 'django.contrib.auth.middleware.AuthenticationMiddleware', 'django.contrib.auth.middleware.SessionAuthenticationMiddleware', 'django.contrib.messages.middleware.MessageMiddleware', 'django.middleware.clickjacking.XFrameOptionsMiddleware', )
但是,No 'Access-Control-Allow-Origin' header is present on the requested resource.
每当我点击任何API时,我都会收到错误Rest Framework
.如果我设置了CORS_ORIGIN_ALLOW_ALL = True
,那么API的工作正常,但对我的服务器端数据来说是非常不安全的.
我需要更改什么来解决这个问题?