1pip install django-cors-headers
2
3#Add corsheaders to installed applications in settings.py:
4
5INSTALLED_APPS = [
6 ...
7 'corsheaders',
8]
9
10#Add corsheaders.middleware.CorsMiddleware to middleware section in settings.py:
11
12MIDDLEWARE = [
13 'corsheaders.middleware.CorsMiddleware',
14 'django.middleware.security.SecurityMiddleware',
15 'django.contrib.sessions.middleware.SessionMiddleware',
16 'django.middleware.common.CommonMiddleware',
17 ...
18
19]
20
21#Allow access to all domains by setting the following variable to TRUE in settings.py:
22DEBUG = True
23
24ALLOWED_HOSTS = []
25
26CORS_ORIGIN_ALLOW_ALL = True
27
28