当前位置: 首页 > news >正文

FLASK创建下载

html用a标签

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

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

from flask import Flask, render_template, send_from_directory
@app.route('/download/<filename>')
def download_file(filename):# Send the image file to the clientreturn 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.

http://www.lryc.cn/news/521467.html

相关文章:

  • 漫话架构师|什么是系统架构设计师(开篇)
  • Web Socket
  • JavaSE学习心得(反射篇)
  • 使用FRP进行内网穿透
  • 长安“战疫”网络安全公益赛的一些随想
  • flutter 安卓端打包
  • Cesium中的CustomDataSource 详解
  • [Qt]常用控件介绍-按钮类控件-QPushButton、QRedioButton、QCheckBox、QToolButton控件
  • Windows 蓝牙驱动开发-安装蓝牙设备
  • element表格有横向滚动条时产生错位或者偏移(火狐浏览器)
  • C# 下 SQLite 并发操作与锁库问题的 5 种解决方案
  • 2025封禁指定国家ip-安装xtables-addons记录
  • 卷积神经02-CUDA+Pytorch环境安装
  • 高斯数据库与MySQL数据库的区别
  • 【 PID 算法 】PID 算法基础
  • 【AI】【RAG】如何通过WebUI部署与优化RAG问答系统
  • SpringBoot之OriginTrackedPropertiesLoader类源码学习
  • 51单片机 AT24C02(I2C总线)
  • Shell正则表达式与文本处理三剑客(grep、sed、awk)
  • Docker Desktop 中安装 MySQL 并开启远程访问的详细教程
  • 计算机网络 (39)TCP的运输连接管理
  • 麦田物语学习笔记:构建游戏的时间系统
  • Tauri教程-进阶篇-第二节 命令机制
  • candb++ windows11运行报错,找不到mfc140.dll
  • 提供的 IP 地址 10.0.0.5 和子网掩码位 /26 来计算相关的网络信息
  • vscode离线安装插件--终极解决方案
  • LabVIEW启动时Access Violation 0xC0000005错误
  • string(一)
  • 计算机网络 (41)文件传送协议
  • C++ STL之容器介绍(vector、list、set、map)