下载本地文件就是找到文件路径 调用flask自带的send_file(路径)下载, 并返回
flask:
# 下载文件
from flask import send_file@task_mgm.route('/taskinfo_download=<string:filename>')@sso_wrapperdef taskinfo_download(filename):
UPLOAD_FOLDER = 'app/controls/task_mgm/task_files/' ROOT_FOLDER = os.path.join(os.getcwd(), UPLOAD_FOLDER) # 整合绝对路径 response = make_response(send_file(ROOT_FOLDER + filename))return response
js:
// 下载文件 $("#download").click(function () { if(confirm('确定下载?')){ var filename = $('#download').val(); // $.get('/task_mgm/taskinfo_download='+filename) if(filename){ window.location.href='/task_mgm/taskinfo_download='+filename } else { alert('下载失败') } } });