PriceyCash
PriceyCash

Reputation: 11

'corsheaders' could not be found but it is installed

I am trying to add the cors header as instructed by https://pypi.org/project/django-cors-headers/

However, when I try to run the server i get 'Module not found: corsheaders', even though it is installed. Any idea what could be wrong?

settings.py

# Application definition
INSTALLED_APPS = [
    'django.contrib.admin',
    'django.contrib.auth',
    'django.contrib.contenttypes',
    'django.contrib.sessions',
    'django.contrib.messages',
    'django.contrib.staticfiles',
    'rest_framework',
    'rest_framework.authtoken',
    'corsheaders',
    'api',
]


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_ALLOW_ALL_ORIGINS = True

Upvotes: 0

Views: 3945

Answers (1)

Nurullo Salaydinov
Nurullo Salaydinov

Reputation: 11

This kind of problem went me so I tried to create virtual environment

python -m venv env

After created activate it.

source env/bin/activate

or windows cd env/Scripts then activate

finally install your packages and run server

  • pip install django

  • pip install djangorestframework

  • pip install django-cors-headers

Upvotes: 1

Related Questions