Python使用flask架构、跨域

from flask import Flask
import json
from flask_cors import CORS


Server = Flask(__name__)
cors = CORS(Server, supports_credentials=True)
Server.debug=True

@Server.route('/')
def hello_world():
    return 'Hello World!'

@Server.route('/login',methods=['POST'])
def login():
    return '{"code":1,"msg":"success","data":""}'


if __name__ == '__main__':
    Server.run(host='127.0.0.1',port=9003)

需要导入两个包 pip install flask、pip install flask_cors

flask_cors可以解决浏览器的跨域问题

posted @ 2020-07-13 17:30  zebra_彬  阅读(389)  评论(0编辑  收藏  举报