Django解决跨域问题
安装django-cors-headers 使用pip安装 1 pip install django-cors-headers 官方文档:adamchainz/django-cors-headers: Django app for handling the server headers required for Cross-Origin Resource Sharing (CORS) (github.com) 中文文档:django-cors-headers - Lowell - 博客园 (cnblogs.com) 配置 在APP中注册 1 2 3 4 5 INSTALLED_APPS = [ ..., "corsheaders", ..., ] 添加中间件 1 2 3 4 5 6 MIDDLEWARE = [ ..., "corsheaders.middleware.CorsMiddleware", "django.middleware.common.CommonMiddleware", ..., ] CorsMiddleware should be placed as high as possible, especially before any middleware that can generate responses such as Django’s CommonMiddleware or Whitenoise’s WhiteNoiseMiddleware....