Django Corsのインストールと設定


設定

# Bash
> pip install django-cors-headers

設定

# /mysite/settings.py
from corsheaders.defaults import default_headers

# Application definition
INSTALLED_APPS = [
    'corsheaders',
    # ...
]

MIDDLEWARE = [
    'corsheaders.middleware.CorsMiddleware',
    # ...
]

# CORS
CORS_ORIGIN_WHITELIST = [
    'http://localhost:3000',
]
CORS_ALLOW_CREDENTIALS = True
CORS_ALLOW_HEADERS = list(default_headers) + [ 'token' ]