How to Solve Access-Control-Allow-Origin issue in Django

0
417
Django development

1. Access-Control-Allow-Origin for Calling API in Angular

Change your settings.py file and add code in Middleware

Install Corsheader package in Django, and define in INSTALLED_APP

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

LEAVE A REPLY

Please enter your comment!
Please enter your name here