• 引入django-cors-headers: pip3 install django-cors-headers
    • 添加到INSTALLED_APPS中:

      1. # settings.py
      2. INSTALLED_APPS = [
      3. ......
      4. 'corsheaders',
      5. ]
    • 配置MIDDLEWARE,添加的跨域配置尽量放在’django.middleware.csrf.CsrfViewMiddleware’之前

      1. # settings.py
      2. MIDDLEWARE = [
      3. ......
      4. 'corsheaders.middleware.CorsMiddleware',
      5. ]
    • 配置CORS_ORIGIN_ALLOW_ALL = True