3

I am a newbie to Django and trying to enable CORS for my server. I couldn't find a built-in solution so I went with django-cors-headers. I am running my server in conda environment on python 3.5 in Ubuntu 15.04. So I installed it with pip3 install django-cors-header. When I do pip3 list it shoes django-cors-header installed at version 1.2.2. In my django app I did.

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

But when I run python3 manage.py runserver It stops saying ImportError: No module named 'corsheaders'. I have read all SO posts regarding it but none seem to solve my problem. Kindly help

Saras Arya
  • 3,022
  • 8
  • 41
  • 71

4 Answers4

14

Originally I did pip3 install django-cors-headers, instead by fluke I tried pip install django-cors-headers and voila it worked.

Hope it helps somebody

LondonAppDev
  • 8,501
  • 8
  • 60
  • 87
Saras Arya
  • 3,022
  • 8
  • 41
  • 71
0

I think you suppose to type the following command

pip3 install django-cors-headers

Hope this can help

Valdèse Kamdem
  • 150
  • 1
  • 11
0

I had a similar issue. In my case, Pip was installing Packages Into global environment While VirtualEnv was Activated. So following command worked for me-

<path-to-your-env>/bin/pip3 install -r requirements.txt
Suyash Soni
  • 219
  • 2
  • 9
-1

Same thing happened to me. I just forgot to run:

pipenv shell
Julien Le Coupanec
  • 7,742
  • 9
  • 53
  • 67