Falsk解决后端跨域问题
作者:互联网
- 先下载对应的包
pip install flask_cors
- 导入包
from flask_cors import CORS
- 创建app后中写入
CORS(app, resources=r'/*')
示例代码如下:
1 from flask import Flask 2 from flask_cors import CORS 3 from flask_mail import Mail 4 from config import APP_ENV, config,API_VERSION 5 6 mail = Mail() 7 8 def create_app(): 9 """ 10 工厂函数,创建APP实例 11 :return app实例 12 """ 13 setupLogging(config[APP_ENV].LOGGING_LEVEL) 14 15 app = Flask(__name__) 16 app.config.from_object(config[APP_ENV]) 17 18 CORS(app, resources=r'/*') 19 20 app.after_request(after_request) 21 22 # 创建Redis数据库连接对象 23 global redis_conn 24 redis_conn = redis.StrictRedis(host=config[APP_ENV].REDIS_HOST, port=config[APP_ENV].REDIS_PORT)
标签:跨域,后端,flask,APP,Falsk,ENV,import,config,app 来源: https://www.cnblogs.com/yyf993/p/16359071.html