当前位置:首页 > 技术教程 > 正文

解决flask跨域问题

解决flask跨域问题 第1张

1.解决flask 跨域问题方法介绍:

pip install flask-cors from flask_cors import CORS CORS(app, resources=r‘/*‘)

2.如果使用nginx代理,无需使用方法1,解决nginx跨域

location / { add_header‘Access-Control-Allow-Origin’‘*’; Add_Header"accesscontrolallowscredentials"true"; add_header'Access-Control-Allow-Methods''GET,POST,PUT,DELETE,PATCH,OPTIONS'; Add_Header"accesscontrolallowedheader"username,appName,signature,timestamp,DNT,x-mx-reqtoken,keepalive,useragent,x-requested-with(ifselfmodified),cachecontrol,contenttype,authorization,token‘; Includinguwsgi_Parameters; uwsgi_pass127.0.0.1:8630; }

把上面配置复制,替换nginx的location配置即可。

以上是关于“解决flask跨域问题 ”的介绍,如需购买云服务器,推荐使用西西云,独享IP,弹性灵活各种配置任您选配,最低只需要43/月,免费帮助配置环境,挂载磁盘等,协助处理简单问题,同时提供快速0元备案,让您快速运营,详情请咨询西西云。

产品选购地址:

解决flask跨域问题 第2张

https://www.kufanyun.com/server/buy.html

解决flask跨域问题 第3张

0