python下载文件
程序员文章站
2022-04-08 23:16:55
...
from flask import Flask,request,Response
app = Flask(__name__)
@app.route('/', methods=["GET"])
def download():
file = request.args.get("file", 0)
f = open(file,'r')
data = f.read()
f.close()
return Response(data, content_type='application/octet-stream',headers={
'Content-Disposition':'attachment; filename={}'.format(f.name)
})
if __name__ == '__main__':
app.run(host='0.0.0.0',
threaded=True,
debug=False,
port=8080)