Skip to content Skip to sidebar Skip to footer

Cross Origin Access Issues - Django 2.1.7

I have gone through literally all SO links, reinstalled django and django-cors-headers and followed this to the T and yet we get pre flight error cross origin not allowed Django

Solution 1:

CorsMiddleware should be placed as high as possible, especially before any middleware that can generate responses such as Django’s CommonMiddleware or Whitenoise’s WhiteNoiseMiddleware. If it is not before, it will not be able to add the CORS headers to these responses.

MIDDLEWARE = [

    'corsheaders.middleware.CorsMiddleware',        # <-- should be at the top'django.middleware.security.SecurityMiddleware',
    'django.contrib.sessions.middleware.SessionMiddleware',
    'django.middleware.common.CommonMiddleware',
    'corsheaders.middleware.CorsPostCsrfMiddleware',
    'django.middleware.csrf.CsrfViewMiddleware',
    'django.contrib.auth.middleware.AuthenticationMiddleware',
    'django.contrib.messages.middleware.MessageMiddleware',
    'django.middleware.clickjacking.XFrameOptionsMiddleware',
]

Solution 2:

This is an issue is because the given Django package is for Djangov2.2> Here you are using 2.1 so it doesn't support it.

You need to manually pass headers from HttpResponse

Post a Comment for "Cross Origin Access Issues - Django 2.1.7"