Flask download file vs django download file
Only difference is make_response and httpresponse.
FLASK VERSION:
from flask import make_response
@app.route('/jobstatus_download/')
def jobstatus_download():
with open('Job_status.csv', 'w') as f:
writer = csv.writer(f)
for row in sysdb_connection():
writer.writerow(row)
with open('Job_status.csv') as f:
c = f.read()
response = make_response(c)
response.headers['Content-Type'] = 'application/octet-stream'
response.headers['Content-Disposition'] = 'attachment;filename="{0}"'.format('Job_status.csv')
return response
Django Version:
from django.http import HttpResponse
def snooper_download(request):
with open('snooper_impact.csv', 'w') as f:
writer = csv.writer(f)
for row in cursor.fetchall():
writer.writerow(row)
with open('snooper_impact.csv') as f:
c = f.read()
response = HttpResponse(c)
response['Content-Type'] = 'application/octet-stream'
response['Content-Disposition'] = 'attachment;filename="{0}"'.format('snooper_impact.csv')
return response
Flask download file vs django download file的更多相关文章
- Set a static file on django
1. In setting file: ROOT_PATH='/home/ronglian/project/taskschedule' STATIC_URL = '/static/' STATICFI ...
- Django Manage File
default_storage >>> from django.core.files.base import ContentFile >>> from django ...
- Cannot open include file: 'initializer_list': No such file or directory
Cannot open include file: 'initializer_list': No such file or directory今天使用VS2012编译一个项目的时候,遇到了这个问题,上 ...
- How to Convert a Class File to a Java File?
What is a programming language? Before introducing compilation and decompilation, let's briefly intr ...
- Visual Studio发布Web项目报错:Unable to add 'xxx' to the Web site. Unable to add file 'xxx'. The specified file could not be encrypted.
背景 Visual Studio下的Web项目 现象 发布时遇到Unable to add 'xxx' to the Web site. Unable to add file 'xxx'. The ...
- 配置tomcat连接器后,启动服务报错“No Certificate file specified or invalid file format"异常
1:原来的配置是 <Connector port="8443" protocol="HTTP/1.1" SSLEnabled="true&quo ...
- 配置CAS错误No Certificate file specified or invalid file format
配置tomcat证书 keystore文件后启动一直报错:(tomcat版本:apache-tomcat-6.0.43) tomcat配置: <Connector port="8443 ...
- ShopEx访问提示Incompatible file format: The encoded file has format major ID 2, whereas the Loader expects 4
今天测试了下ShopEx程序,但是ShopEx安装时(程序放在public_html目录下的test目录中)遇到了问题,提示错误如下:Fatal error: Incompatible file fo ...
- Qt Creator编译时:cannot open file 'debug\QtGuiEx.exe' File not found
Qt Creator编译时:cannot open file 'debug\QtGuiEx.exe' File not found 利用Qt Creator编译工程时,出现如题目所示的错误,其中红色部 ...
随机推荐
- 卷积神经网络(CNN)的训练及代码实现
本文部分内容来自zouxy09的博客.谢谢.http://blog.csdn.net/zouxy09/article/details/9993371 以及斯坦福大学深度学习教程:http://ufld ...
- java 抽象类实现接口
1.抽象类肯定可以实现接口: 2.这不是有没有意义的事情,是一种思想,当你自己写的类想用接口中个别方法的时候(注意不是所有的方法),那么你就可以用一个抽象类先实现这个接口(方法体中为空),然后再用你 ...
- hive批量执行sql命令及使用小技巧
root@hadoop-senior hive-0.13.1]$ bin/hive -helpusage: hive -d, --define <key=value> Variable s ...
- ACM解题之(ZOJ 1094) Matrix Chain Multiplication
题目来源: 点击打开链接 题目翻译: 矩阵乘法问题是动态规划的典型例子. 假设你必须评估一个表达式,如A * B * C * D * E,其中A,B,C,D和E是矩阵.由于矩阵乘法是关联的,乘法运算的 ...
- 内置函数(Day16)
现在python一共为我们提供了68个内置函数.它们就是python提供给你直接可以拿来使用的所有函数 内置函数 abs() divmod() input() open() stati ...
- LeetCode:平衡二叉树【110】
LeetCode:平衡二叉树[110] 题目描述 给定一个二叉树,判断它是否是高度平衡的二叉树. 本题中,一棵高度平衡二叉树定义为: 一个二叉树每个节点 的左右两个子树的高度差的绝对值不超过1. 示例 ...
- Python 3 文件和字符编码
一.文件: 打开文件的模式有: r,只读模式(默认). w,只写模式. 不可读,不存在则创建:存在则删除内容 a,追加模式. 可读,不存在则创建:存在则只追加内容 "+"表示可以 ...
- iOS 什么是函数式编程
前言:当前只做理解性的常规背书,根据不断深入学习会不断丰富解读内容,欢迎评论提意见 函数式编程:Functional Programming 1 基本解释: 函数式编程 是一种思维模式,一种编程思想, ...
- Rabbitmq消费失败死信队列
Rabbitmq 重消费处理 一 处理流程图: 业务交换机:正常接收发送者,发送过来的消息,交换机类型topic AE交换机: 当业务交换机无法根据指定的routingkey去路由到队列的时候,会全部 ...
- [转] 我所经历的IBM SOA与系统整合
2006年,一汽大众新上来一位总经理,新加坡人,整个一国际背景高端管理人才,是德国人和中国人博弈后取得的胜利. 一汽大众过去是从总部到区域到终端一体化的大盘管理模式,很僵化很粘稠,不利用快速反应.于是 ...