Django设置允许跨域访问

  • 安装django-cors-headers
pip install django-cors-headers
  • 修改settings.py
INSTALLED_APPS = [
    ......
    'corsheaders',
    ......
]

MIDDLEWARE = [
    ......
    'corsheaders.middleware.CorsMiddleware',
    'django.middleware.common.CommonMiddleware',
    ......
]

CORS_ORIGIN_ALLOW_ALL = True
CORS_ALLOW_CREDENTIALS = True

你可能感兴趣的:(Django设置允许跨域访问)