【发布时间】:2018-06-23 05:15:06
【问题描述】:
嗯,一开始我忘记了中间件类,但添加之后就很好用了(一周前)。
现在,我回到我的工作站,发现它再次无法工作。
ACCESS_CONTROL_ALLOW_ORIGIN 标头根本没有设置。
我已经尝试了所有方法,将中间件放在顶部,CommonMiddleware 之前,但它不起作用。
这是我的 setting.py 文件:
DEBUG = True
ALLOWED_HOSTS = ['*']
# Application definition
INSTALLED_APPS = [
'account',
'corsheaders',
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
'social_django',
]
# if DEBUG:
# INSTALLED_APPS += 'corsheaders',
# MIDDLEWARE = ['corsheaders.middleware.CorsMiddleware', ]
# else:
# MIDDLEWARE = []
MIDDLEWARE = [
'django.middleware.security.SecurityMiddleware',
'django.contrib.sessions.middleware.SessionMiddleware',
'corsheaders.middleware.CorsMiddleware',
'django.middleware.common.CommonMiddleware',
'django.middleware.csrf.CsrfViewMiddleware',
'django.contrib.auth.middleware.AuthenticationMiddleware',
'django.contrib.messages.middleware.MessageMiddleware',
'django.middleware.clickjacking.XFrameOptionsMiddleware',
]
CORS_ORIGIN_ALLOW_ALL = DEBUG
这是我得到的回复:
Date: Sun, 14 Jan 2018 09:35:09 GMT
Server: WSGIServer/0.1 Python/2.7.14+
X-Frame-Options: SAMEORIGIN
Content-Type: text/html; charset=utf-8
Content-Length: 146
【问题讨论】:
-
我也有同样的问题。你找到解决办法了吗?
标签: python django django-cors-headers