flask框架实现文件下载功能

传入文件名即可下载文件

from flask import Flask, send_file, Response, send_from_directory
app = Flask(__name__)


@app .route("/download")
def download():
	"""读取本地excel文件接口"""
	path = request.args["path"].replace("_","/")
	with open("result/%s" % path,"rb") as f:
		stream = f.read()
	response = Response(stream, content_type='application/octet-stream')
	response.headers['Content-disposition'] = 'attachment; filename=%s' % request.args["path"].split("_")[1]

	return response

你可能感兴趣的:(flask,python,后端)