安装依赖
pip install flask -i https://pypi.douban.com/simple
pip install flask_cors -i https://pypi.douban.com/simple
简单示例
from flask import Flask, request, send_from_directory, jsonify
from flask_cors import CORS
app = Flask(__name__)
CORS(app)
@app.route('/hello')
def hello():
return 'hello world'
@app.route('/upload', methods=['POST'])
def upload():
f = request.files['filename']
f.save('xxx.txt')
return jsonify({'message': 'upload success'})
@app.route('/download/<path:name>')
def download(name):
return send_from_directory(r'E:\xxx\xxx', name, as_attachment=True)
if __name__ == '__main__':
app.run(host='0.0.0.0', port=8080, debug=True)
启动
python app.py