1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27
| # install django-cors-headers $ pip install django-cors-headers
# add apps in settings.py INSTALLED_APPS = [ ... 'corsheaders', ... ]
# add middleware in settings.py MIDDLEWARE = [ ... 'corsheaders.middleware.CorsMiddleware', 'django.middleware.common.CommonMiddleware', ... ]
# add config in settings.py CORS_ORIGIN_ALLOW_ALL = True # If this is used then `CORS_ORIGIN_WHITELIST` will not have any effect CORS_ALLOW_CREDENTIALS = True CORS_ORIGIN_WHITELIST = [ 'http://localhost:3030', ] # If this is used, then not need to use `CORS_ORIGIN_ALLOW_ALL = True` CORS_ORIGIN_REGEX_WHITELIST = [ 'http://*.example.com:3030', ]
|