Django giving error ImportError: No module named 'corsheaders'
Django giving error ImportError: No module named 'corsheaders'
我是 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 帖子,但 none 似乎解决了我的问题。
请帮助
最初我做了 pip3 install django-cors-headers
,而不是侥幸,我尝试了 pip install django-cors-headers
,瞧,它成功了。
希望对大家有所帮助
我想你应该输入以下命令
pip3 install django-cors-headers
希望对您有所帮助
同样的事情发生在我身上。我只是忘了 运行:
pipenv shell
我遇到了类似的问题。在我的例子中,Pip 在 VirtualEnv 被激活时将包安装到全局环境中。所以下面的命令对我有用-
<path-to-your-env>/bin/pip3 install -r requirements.txt
我是 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 帖子,但 none 似乎解决了我的问题。
请帮助
最初我做了 pip3 install django-cors-headers
,而不是侥幸,我尝试了 pip install django-cors-headers
,瞧,它成功了。
希望对大家有所帮助
我想你应该输入以下命令
pip3 install django-cors-headers
希望对您有所帮助
同样的事情发生在我身上。我只是忘了 运行:
pipenv shell
我遇到了类似的问题。在我的例子中,Pip 在 VirtualEnv 被激活时将包安装到全局环境中。所以下面的命令对我有用-
<path-to-your-env>/bin/pip3 install -r requirements.txt