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. Sql Server 2005 .bak备份文进行还原数据库

    https://jingyan.baidu.com/article/9158e000250b91a25412283f.html https://www.cnblogs.com/webmen/p/575 ...

  2. tfboys——tensorflow模块学习(二)

    tf.contrib模块 tf.contrib 模块是一个比较复杂的模块. contrib细节: tf.contrib.bayesflow.entropy  香农信息论 tf.contrib.baye ...

  3. (转)fiddler使用简介--其三

    原文地址:http://www.cnblogs.com/miantest/p/7294620.html 我们知道Fiddler是位于客户端和服务器之间的代理,它能够记录客户端和服务器之间的所有 HTT ...

  4. docker快速构建oracle数据库

    1.查看可用镜像docker search oracle2.拉去想要的镜像docker pull wnameless/oracle-xe-11g3.基于wnameless/oracle-xe-11g创 ...

  5. LeetCode-day05

    45. Single Number 在个数都为2的数组中找到个数为1的数 46. Missing Number 在数组中找到从0到n缺失的数字 47. Find the Difference 找两个字 ...

  6. id函数

    描述 id() 函数用于获取对象的内存地址. 语法 id 语法: id([object]) 参数说明: object -- 对象. 返回值 返回对象的内存地址. 实例 以下实例展示了 id 的使用方法 ...

  7. Python 4 函数的参数,内置函数,装饰器,生成器,迭代器,

    一.函数的参数: 1.位置参数:调用函数时根据函数定义的参数位置来传递参数. 2.关键字参数:用于函数调用,通过“键-值”形式加以指定.可以让函数更加清晰.容易使用,同时也清除了参数的顺序需求. 3. ...

  8. rails 增删改查

    class InvoicesController < ApplicationController def index @invoices = Invoice.all end def show @ ...

  9. 42和为S的两个数字

    题目描述 输入一个递增排序的数组和一个数字S,在数组中查找两个数,是的他们的和正好是S,如果有多对数字的和等于S,输出两个数的乘积最小的. 输出描述: 对应每个测试案例,输出两个数,小的先输出. 设置 ...

  10. Linux常用指令——周琛

    ps ax | grep java 查看进程命令里带“java”字样的进程信息,第一列是进程号 kill -9 1234 强制杀死1234号进程 cd /xxx/xxx 进入/xxx/xxx目录 cd ...