FLASK创建下载

html用a标签

html 复制代码
<!-- Button to download the image -->
<a href="{{ url_for('download_file', filename='image.png') }}">
   <button>Download Image</button>
</a>

后端:url_for双大括号即是用来插入变量到模板中的语法。也就是绑定了函数download_file()

python 复制代码
from flask import Flask, render_template, send_from_directory
@app.route('/download/<filename>')
def download_file(filename):
    # Send the image file to the client
    return send_from_directory(app.config['UPLOAD_FOLDER'], filename,as_attachment=True)

Flask Route /download/<filename> : When the button is clicked, it triggers the /download/<filename> route, which uses send_from_directory to serve the image file stored in the static/images directory.

相关推荐
iuuia11 小时前
02--CSS基础
前端·css
kyle~11 小时前
Qt---setAttribute设置控件或窗口的内部属性
服务器·前端·c++·qt
FIN666811 小时前
昂瑞微:射频与模拟芯片领域的国产领军者
前端·人工智能·科技·前端框架·智能
苦夏木禾11 小时前
css实现表格中最后一列固定
前端·javascript·css
LuHang12 小时前
WebSocket服务封装实践:从连接管理到业务功能集成
前端·websocket
九十一12 小时前
vue2中$set的原理
前端
Kaydeon12 小时前
【AIGC】50倍加速!NVIDIA蒸馏算法rCM:分数正则化连续时间一致性模型的大规模扩散蒸馏
人工智能·pytorch·python·深度学习·计算机视觉·aigc
闲不住的李先森12 小时前
深入解析 Cursor 规则:为团队打造统一的 AI 编程规范
前端·ai编程·cursor
FlowGram12 小时前
FlowGram 官网建设
前端