您在问题中引用的链接建议使用django-cors-headers
,其documentation表示安装库
python -m pip install django-cors-headers
然后将其添加到已安装的应用程序中:
INSTALLED_APPS = (
...
'corsheaders',
...
)
您还需要添加一个中间件类来监听响应:
MIDDLEWARE = [
...,
'corsheaders.middleware.CorsMiddleware',
'django.middleware.common.CommonMiddleware',
...,
]
并指定COR的域,例如:
CORS_ALLOWED_ORIGINS = [
'http://localhost:3030',
]
请浏览the configuration section篇文档,特别注意CORS_ORIGIN_
的各种设置.你需要根据自己的需要设置一些.