$ pipenv install django-cors-headers
# or
$ pip install django-cors-headers
Install from pip:
python -m pip install django-cors-headers
and then add it to your installed apps:
INSTALLED_APPS = [
...,
"corsheaders",
...,
]
You will also need to add a middleware class to listen in on responses:
MIDDLEWARE = [
...,
"corsheaders.middleware.CorsMiddleware",
"django.middleware.common.CommonMiddleware",
...,
]
MIDDLEWARE = [
...
'corsheaders.middleware.CorsMiddleware',
'django.middleware.common.CommonMiddleware',
...
]
python -m pip install django-cors-headers
CORS_ALLOWED_ORIGINS = [
"https://example.com",
"https://sub.example.com",
"http://localhost:8080",
"http://127.0.0.1:9000"
]
INSTALLED_APPS = [
...,
"corsheaders",
...,
]
INSTALLED_APPS = [
...
'corsheaders',
...
]
include origin header in your request
headers:{
'Content-Type':'application/json',
'origin':'*',
}