How to setup & install Django Cors Header

why we use Cors Headers in djnago:

Simple, we need to communicate our application to other application we need to allow that url in our application, So we use this cors headers.

how to Setup

first install - pip install django-cors-headers

Then goto settings.py:

INSTALLED_APPS = (
    ...
    'corsheaders',
    ...
)
 CORS_ORIGIN_WHITELIST = (
    'https://localhost:3001', #your allowed urls    'https://127.0.0.1:3001')

CORS_ORIGIN_ALLOW_ALL = True
 MIDDLEWARE_CLASSES = (
    ...
    'corsheaders.middleware.CorsMiddleware',  
    'django.middleware.common.CommonMiddleware',  
    ...
)
 After your run your application and Open your browser in cors disable mode:
How to open in Browser cors disable mode:
open terminal and type --> google-chrome --disable-web-security
its open browser - type your CORS_ORIGIN_WHITELIST allowed url then its work.
 
 
 
 

Comments

Popular posts from this blog

How to Connect Firebase Using Pyrebase In Python

How to get Full URL or get absolute url In Django

How To Convert Html File/URL/String Into Image Using Python