flask 下載本地文件


下載本地文件就是找到文件路徑  調用flask自帶的send_file(路徑)下載, 並返回

flask:

# 下載文件

from flask import send_file
@task_mgm.route('/taskinfo_download=<string:filename>')
@sso_wrapper
def 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('下載失敗')
}
}
});

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM