2、Python djang 框架下的word Excel TXT Image 等文件的下载
2、python实现文件下载
(1)方法一、直接用a标签的href+数据库中文件地址,即可下载。缺点:word excel是直接弹框下载,对于image txt 等文件的下载方式是直接在新页面打开。
(2)方法二、在python后台对下载内容进项处理,返回内容直接弹出下载框。
#后台处理函数
def downloadFile(req):
filename=basePath+req.GET['url']
def file_iterator(file_name, chunk_size=512):
with open(file_name) as f:
while True:
c = f.read(chunk_size)
if c:
yield c
else:
break
response = StreamingHttpResponse(file_iterator(filename))
response['Content-Type'] = 'application/octet-stream'
response['Content-Disposition'] = 'attachment;filename="{0}"'.format(filename)
return response
(3)前台使用函数方法
①、a标签调用函数传入路径<a href='/downloadFile/url=路径'>
②、button标签调用jq方法调用后台函数
<input type='button' class='download'>
#下载按钮点击事件
$("body").on("click",".download",function(){ location.href="/downloadFile/?url="+路径;
});
2、Python djang 框架下的word Excel TXT Image 等文件的下载的更多相关文章
- 1、Python django 框架下的word Excel TXT Image 等文件的上传
1.文件上传(input标签) (1)html代码(form表单用post方法提交) <input class="btn btn-primary col-md-1" styl ...
- 在线文档转换API word,excel,ppt等在线文件转pdf、png
在线文档转换API提供word,excel,ppt等在线文件转pdf.png等,文档:https://www.juhe.cn/docs/api/id/259 接口地址:http://v.juhe.cn ...
- react框架下,在页面内加载显示PDF文件,关于react-pdf-js的使用注意事项
react框架下,在页面内加载显示PDF文件,关于react-pdf-js的使用注意事项 之前做了一个需求,在注册账号的时候,让用户同意服务条款, 服务条款是一个PDF文件, 这就需要在react内加 ...
- Thinkphp框架下PHPExcel实现Excel数据的批量化导入导出
第一步:下载官方的PHPExcel文件,下载地址https://github.com/PHPOffice/PHPExcel 第二步:解压打开,将PHPExcel\Classes\全部文件拷贝到thin ...
- python 查找目录下 文件名中含有某字符串的文件
有坑的地方: 如果代码写成这样: [( os.path.abspath(x)) for x in os.listdir(startPath) ] 此代码只能用于当前目录下,listdir列出的都只是文 ...
- python基础——15(加密、excel操作、ini文件操作、xml操作模块及数据格式分类)
一.加密模块 1.有解密的加密方式(base64) #base64加密 import base64 str_encrypt = input("输入要加密的字符串:\n") base ...
- ASP.NET MVC在线预览Excel、Word、TXT、PDF文件
代码: using System; using System.Collections.Generic; using System.Linq; using System.Web; using Syste ...
- Python交互模式下方向键出现乱码
解决办法如下: 1.安装readline模块 readline库是bash shell用的库,包含许多功能,如命令行自动补全等. ubuntu下安装的命令: sudo apt-get instal ...
- C#创建Excel(.xls和.xlsx)文件的三种方法
生成EXCEL文件是经常需要用到的功能,我们利用一些开源库可以很容易实现这个功能. 方法一:利用excellibrary,http://code.google.com/p/excellibrary/ ...
随机推荐
- poj 2553 The Bottom of a Graph【强连通分量求汇点个数】
The Bottom of a Graph Time Limit: 3000MS Memory Limit: 65536K Total Submissions: 9641 Accepted: ...
- hdoj1754 I Hate It【线段树区间最大值维护+单点更新】
I Hate It Time Limit: 9000/3000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total S ...
- SpringMVC 测试 mockMVC
SpringMVC测试框架 基于RESTful风格的SpringMVC的测试,我们可以测试完整的Spring MVC流程,即从URL请求到控制器处理,再到视图渲染都可以测试. 一 MockMvcBui ...
- PHP环境配置综合篇
1.WNMP: http://www.wnmp.com.cn/ En: https://www.getwnmp.org/ 2.xampp:https://www.apachefriends.o ...
- SDWebImage原理小结
先贴上github上的地址:https://github.com/rs/SDWebImage,至于安装方式这里就不多说了,它的框架说明中都有,不过建议使用cocoaPod来安装比较好,方便日后的维护代 ...
- 有n个台阶,如果一次只能上1个或2个台阶,求一共有多少种上法
// n级台阶,求多少种跳法.cpp : Defines the entry point for the console application. // /* 思路: 如果只有一级台阶,n=1,很明显 ...
- [C#] 常用工具类——系统日志类
using System; using System.Collections.Generic; using System.Text; using System.Diagnostics; namespa ...
- C#通过FTP账号上传、修改、删除文件 FTPClient
下面类文件中,主要做的工作是:从ftp服务器上下载文件把本地文件替换.添加.或删除功能,在替换本地文件时会先备份一下本地的文件,若整个操作都完成了就会发出commit命令,表示全部替换成功.若中间操作 ...
- 【转】jsoncpp在xcode中的使用
http://blog.csdn.net/ashqal/article/details/8573392 考虑到cocos2dx需要使用jsoncpp做关卡的设置, 尝试用源代码直接放到项目以方便后期生 ...
- Load resources from classpath in Java--reference
In general classpath is the path where JVM can find .class files and resources of your application a ...