has been blocked by CORS policy: No 'Access-Control-Allow-Origin' header is


 

問題:在本地pycharm上跑沒問題,部署到服務器上就發現表單提交沒反應了,取出火狐調試發現出現如下錯誤,大概意思是被服務器端同源策略攔截導致,因為項目是前后端分離開發,所以服務器會判斷前端屬於跨域請求。

解決方法:

在配置文件中添加如下兩個參數:

CORS_ORIGIN_ALLOW_ALL = True #允許所有源訪問(如果不需要允許全部,可以設置CORS_ORIGIN_WHITELIST=()參數,將需要訪問的域名添加即可)

CORS_ALLOW_CREDENTIALS = True  #是否允許攜帶cookie

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



猜您在找 上傳文件返回413錯誤同時出現has been blocked by CORS policy: No 'Access-Control-Allow-Origin' header... 前端出現has been blocked by CORS policy: No 'Access-Control-Allow-Origin' header is present on the requested resource 跨域詳解 been blocked by CORS policy: No 'Access-Control-Allow-Origin' header is present on the requested resource 跨域詳解 been blocked by CORS policy: No 'Access-Control-Allow-Origin' header is present on the requested resource 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 Access to XMLHttpRequest at 'XXX' from origin 'XX' has been blocked by CORS policy: No 'Access-Control-Allow-Origin' header is present o AJAX跨域請求解決方法 Access to XMLHttpRequest at '*url*' from origin 'null' has been blocked by CORS policy: No 'Access-Control-Allow-Origin' header is present on the requested resource. GET *url* net::ERR_FAILED Access to XMLHttpRequest at 'http://localhost:8090/user/getotp' from origin 'null' has been blocked by CORS policy: No 'Access-Control-Allow-Origin' header is present on the requested resource. 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. 【跨域問題】Access to XMLHttpRequest at ‘A’from ‘B’has been blocked by CORS policy :... No ‘Access-Control-Allow-Origin’ header...(Chrome瀏覽器)
 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM