程序師世界是廣大編程愛好者互助、分享、學習的平台,程序師世界有你更精彩!
首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫知識
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
您现在的位置: 程式師世界 >> 編程語言 >  >> 更多編程語言 >> Python

Django報錯:No ‘Access-Control-Allow-Origin‘ header is present on the requested resource.

編輯:Python

報錯信息:

Access to XMLHttpRequest at 'http://127.0.0.1:8081/api/login/' from origin 'http://127.0.0.1:8080' has been blocked by CORS policy: Response to preflight request doesn't pass access control check: No 'Access-Control-Allow-Origin' header is present on the requested resource.

處理方法:

1. 安裝django-cors-headers

pip install django-cors-headers

2. 修改settings.py

2.1 修改 INSTALLED_APPS

'corsheaders',

2.2 修改MIDDLEWARE

'corsheaders.middleware.CorsMiddleware',
'django.middleware.common.CommonMiddleware',

2.3 追加2處

CORS_ORIGIN_ALLOW_ALL = True
CORS_ALLOW_CREDENTIALS = True

至此Access-Control-Allow-Origin問題排除


  1. 上一篇文章:
  2. 下一篇文章:
Copyright © 程式師世界 All Rights Reserved