【Python 开发之路】跨域处理的各种方法

后端处理

  flask

# pip install flask_cors

from flask_cors import CORS

def create_app():
    app = Flask(__name__)
    CORS(app,resources=r'/*')
    app.register_blueprint(us)
    app.config.from_object("settings.TestingConfig")
    return app
# 方法2
@app.after_request
def cors(environ):
    environ.headers['Access-Control-Allow-Origin']='*'
    environ.headers['Access-Control-Allow-Method']='*'
    environ.headers['Access-Control-Allow-Headers']='x-requested-with,content-type'
    return environ

  Nginx 

location /zy{
           add_header Access-Control-Allow-Origin *;
           add_header Access-Control-Allow-Methods GET,POST,OPTIONS;    
           add_header Access-Control-Allow-Headers X-Requested-With,content-type; 
       proxy_pass http:
//127.0.0.1:5880/;
}

 

posted @ 2022-08-04 15:09  情调丶  阅读(250)  评论(0编辑  收藏  举报