1.安装django-cors-headers
pip install django-cors-headers
2.在setting的INSTALLED_APPS中添加
INSTALLED_APPS = [
...,
"corsheaders",
...,
]
- 在setting的MIDDLEWARE中添加CorsMiddleware
MIDDLEWARE = [
...,
"corsheaders.middleware.CorsMiddleware",
"django.middleware.common.CommonMiddleware",
...,
]
4.允许访问
CORS_ALLOW_ALL_ORIGINS = True