flask 提供文件下载

@app.route(‘/download/<filename>’) def download_file(filename): defsend_file(): store_path = os.path.join(UPLOAD_FOLDER,filename) withopen(store_path, ‘rb’) as targetfile: while1: data = targetfile.read(1 * 1024 * 500) # 每次读取1MB (可用限速) ifnot data: break yield data response = Response(send_file(), content_type=’application/octet-stream’) response.headers[“Content-disposition”] = ‘attachment; filename=%s’ % filename # 如果不加上这行代码,导致下图的问题 return response