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的更多相关文章

  1. Set a static file on django

    1. In setting file: ROOT_PATH='/home/ronglian/project/taskschedule' STATIC_URL = '/static/' STATICFI ...

  2. Django Manage File

    default_storage >>> from django.core.files.base import ContentFile >>> from django ...

  3. Cannot open include file: 'initializer_list': No such file or directory

    Cannot open include file: 'initializer_list': No such file or directory今天使用VS2012编译一个项目的时候,遇到了这个问题,上 ...

  4. How to Convert a Class File to a Java File?

    What is a programming language? Before introducing compilation and decompilation, let's briefly intr ...

  5. 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 ...

  6. 配置tomcat连接器后,启动服务报错“No Certificate file specified or invalid file format"异常

    1:原来的配置是 <Connector port="8443" protocol="HTTP/1.1" SSLEnabled="true&quo ...

  7. 配置CAS错误No Certificate file specified or invalid file format

    配置tomcat证书 keystore文件后启动一直报错:(tomcat版本:apache-tomcat-6.0.43) tomcat配置: <Connector port="8443 ...

  8. 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 ...

  9. Qt Creator编译时:cannot open file 'debug\QtGuiEx.exe' File not found

    Qt Creator编译时:cannot open file 'debug\QtGuiEx.exe' File not found 利用Qt Creator编译工程时,出现如题目所示的错误,其中红色部 ...

随机推荐

  1. boost之实用工具

    1.noncopyable用于禁止复制和拷贝的类继承.声明拷贝和赋值函数为私有,将运行时的错误转化为编译期的错误. #include <iostream> #include <boo ...

  2. getchar,scanf以及缓冲区

    getchar()是stdio.h中的库函数,它的作用是从stdin流中读入一个字符,也就是说,如果stdin有数据的话不用输入它就可以直接读取了.getch()和getche()是conio.h中的 ...

  3. PL/SQL不能格式化SQL:--PL/SQL Beautifier could not parse text

    PL/SQL sql语句美化器点击没有反应.查看下面提示PL/SQL Beautifier could not parse text.本人此次产生的原因是sql语句语法错误. 工具栏处(如果没有此按钮 ...

  4. Incomplete response received from application

    RAILS_ENV=production rake secret 将输出的一大串字码粘贴到rails工程中/config/secrets.yml去,替换掉该文件中的<%= ENV["S ...

  5. json教程系列(2)-生成JSONObject的方法

    生成JSONObject一般有两种方式,通过javabean或者map类型来生成.如下面的例子:   1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 2 ...

  6. 每天一个Linux命令(55)systemctl命令

    systemctl命令是系统服务管理器指令,它实际上将 service 和 chkconfig 这两个命令组合到一起.     (1)用法:     用法:  systemctl  [参数]  [服务 ...

  7. 每天一个Linux命令(49)traceroute命令

        traceroute指令让你追踪网络数据包的路由途径,预设数据包大小是40Bytes.     (1)用法:     用法: traceroute [参数] [主机]   (2)功能:     ...

  8. python中编写无参数decorator

    Python的 decorator 本质上就是一个高阶函数,它接收一个函数作为参数,然后,返回一个新函数. 使用 decorator 用Python提供的 @ 语法,这样可以避免手动编写 f = de ...

  9. centos 下安装python3.6.2

    具体详情: http://www.cnblogs.com/vurtne-lu/p/7068521.html

  10. CCNA 课程 六

    路由协议概述: 通过一种路由协议学习到了多个去往同一目标网络的路由,metric小的放入路由表中.metric一样,同时放进路由表. 通过多种路由协议学习到了去往同一目标网络的路由,路由协议管理距离小 ...