flask 下载 文件 怎么弄?

下面的 不太对

@admin_cfg.route('/download_log', methods=['GET'])
def download_serial_com_log():
    if 'login' not in session:
        return redirect("/")

    lst_file = os.listdir('/root/')
    print(type(lst_file))
    print(lst_file)

    if os.path.exists('/root/down_data.tar'):
        os.remove('/root/down_data.tar')

    str_file_lst = ''
    for item in lst_file:
        print(item)
        # modbus_client_com5.log
        if item.find('modbus_client_com') >= 0:
            str_file_lst = str_file_lst + '/root/' + item + ' '


    if len(str_file_lst) > 0:
        str_cmd = 'tar cvf /root/down_data.tar ' + str_file_lst
        print(str_cmd)
        p = os.popen(str_cmd)
        data = p.read().strip()
        p.close()

    else:
        return send_from_directory("/root/", filename="4g.txt", as_attachment=True)

    return send_from_directory("/root/", filename="down_data.tar", as_attachment=True)
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值