Problem in install django-cors-middleware

I installed django-cors-headers 3.5.0 and I got an error when I tried to run the project. this is my configurations: requirement.txt:

 Django==2.2.0
 djangorestframework==3.9.1,<3.10.0
 psycopg2>=2.7.5,<2.8.0
 Pillow>=5.3.0,<5.4.0
 django-jalali-date==0.3.1
 django-cors-headers==3.5.0

settings.py:

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', #<------There it is
    'core',
    'user',
    'land',
]

MIDDLEWARE = [
    'corsheaders.middleware.CorsMiddleware', # its middleware
    'django.middleware.security.SecurityMiddleware',
    'django.contrib.sessions.middleware.SessionMiddleware',
    '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 = False

CORS_ORIGIN_WHITELIST = (
    'http://localhost:3000',
)

docker-compose:

version: "3"

services:
  app:
    build: 
      context: .
    ports: 
      - "8000:8000"
    volumes:
      - ./app:/app
    command: >
      sh -c "python manage.py wait_for_db &&
             python manage.py migrate &&
             python manage.py runserver 0.0.0.0:8000"
    environment:
      - DB_HOST=db
      - DB_NAME=app
      - DB_USER=postgres
      - DB_PASS=supersecretpassword
    depends_on:
      - db
    container_name: land_api


  db:
    image: postgres:10-alpine
    environment:
      - POSTGRES_DB=app
      - POSTGRES_USER=postgres
      - POSTGRES_PASSWORD=supersecretpassword
    container_name: land_db

but when I run “docker-compose up” i get this error: ModuleNotFoundError: No module named 'corsheaders'

I try to add the installation in dockerFile but it didn’t too. Is it really bug? or I miss something?

Answer

You should rebuild the image after changing requirements.txt:

docker-compose build

Leave a Reply

Your email address will not be published. Required fields are marked *