文件下载

使用a标签下载:

<!DOCTYPE html>  
<html>  
    <head>  
        <meta charset="UTF-8">  
        <title></title>  
    </head>  
    <body>  
        <a href="321.png" download="test.png">点击下载</a>    
    </body>  
</html>

使用window.open下载:

var $eleBtn1 = $("#btn1");  
        var $eleBtn2 = $("#btn2");  
        //已知一个下载文件的后端接口:https://codeload.github.com/douban/douban-client/legacy.zip/master  
        //方法一:window.open()  
        $eleBtn1.click(function(){  
            window.open("https://codeload.github.com/douban/douban-client/legacy.zip/master");  
        });

flask文件下载:

send_from_directory(directory, filename, **options)
  1. directory –所有文件的存储目录。
  2. filename –相对于要下载的目录的文件名。
  3. options –直接转发到的可选关键字参数send_file()。
from flask import Flask, send_from_directory

app = Flask(__name__)

@app.route("/download")
def index():
    return send_from_directory(r"D:\desk\id",filename="123.jpg",as_attachment=True)

if __name__ == '__main__':
    print(app.url_map)
    app.run(host="10.205.1.15", port=5000)

 

posted @ 2021-10-28 21:12  风吹过半夏  阅读(144)  评论(0编辑  收藏  举报