django 跨域解决方案

使用django-cors-headers模块

github:https://github.com/ottoyiu/django-cors-headers

官方文档中有详细说明

简要配置

1、安装

pip install django-cors-headers

2、settings.py文件配置

INSTALLED_APPS = (
    ...
    'corsheaders',
    ...
)

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

CORS_ORIGIN_ALLOW_ALL = True
原文地址:https://www.cnblogs.com/shhnwangjian/p/7646542.html