【发布时间】:2017-03-16 05:31:09
【问题描述】:
我是 Django 的新手,正在尝试为我的服务器启用 CORS。我找不到内置的解决方案,所以我选择了django-cors-headers。我在 Ubuntu 15.04 的 python 3.5 上的 conda 环境中运行我的服务器。所以我用 pip3 install django-cors-header 安装了它。当我执行 pip3 list 时,它会安装在 1.2.2 版的 django-cors-header。在我的 django 应用程序中,我做到了。
INSTALLED_APPS = [
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
'corsheaders',
'polls',
]
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 = True
但是当我运行python3 manage.py runserver 时,它不再说ImportError: No module named 'corsheaders'。
我已经阅读了所有关于它的 SO 帖子,但似乎没有一个能解决我的问题。
请帮忙
【问题讨论】:
标签: django django-cors-headers