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编译工程时,出现如题目所示的错误,其中红色部 ...
随机推荐
- github的代码上传成功但是不显示绿格子(一直拖....心痛的教训.....)
损失了我特么的很多格子啊啊啊啊,必死强迫症啊!!!! 究其原因就是客户端绑定邮箱错误 本地 :git config user.email 显示邮箱是否和github中设定的一样? git config ...
- Python数据分析与挖掘所需的Pandas常用知识
Python数据分析与挖掘所需的Pandas常用知识 前言Pandas基于两种数据类型:series与dataframe.一个series是一个一维的数据类型,其中每一个元素都有一个标签.series ...
- Ip-san 配置过程
1:SAN的定义 SAN是storage area network(存储区域网络)的简写,早期的san采用的是光纤通道技术,后期当iscsi协议出现以后,为了区分两者,就划分了IP SAN和FC SA ...
- 函数编程——匿名函数与lambda(一)
python允许用lambda关键字创造匿名函数. 匿名函数是因为不需要以标准的方式来声明,比如说,使用def语句. 但是,作为函数,它们也能有参数. 一个完整的lambda“语句”代表了一个表达式, ...
- HDU 1159 Common Subsequence(POJ 1458)
Common Subsequence Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) ...
- 42和为S的两个数字
题目描述 输入一个递增排序的数组和一个数字S,在数组中查找两个数,是的他们的和正好是S,如果有多对数字的和等于S,输出两个数的乘积最小的. 输出描述: 对应每个测试案例,输出两个数,小的先输出. 设置 ...
- iOS 事件响应者链的学习(也有叫 UI连锁链)
当发生事件响应的时候,必须知道由谁来响应事件.在iOS中,由响应链来对事件进行响应,所有的事件响应的类都是继承于UIResponder的子类,响应链是一个由不同对象组成的层次结构,其中每个对象将依次获 ...
- asp.net 下载图片
public class DownLoad : IHttpHandler { public void ProcessRequest(HttpContext context) { context.Res ...
- UI控件之UITableView的基本属性
UITableView:特殊的滚动视图,横向固定,可以在纵向上滚动,自动计算contentSize 创建tableView,初始化时指定样式,默认是plain UITableView *_tableV ...
- http://www.uupoop.com/ps/
网页版PS,在线PS 基本的PS功能都有,最重要的一点是快,网页版的嘛,哼哼!