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编译工程时,出现如题目所示的错误,其中红色部 ...
随机推荐
- docker daemon.json 配置
下面是自己设置的 /etc/docker/daemon.json 文件中的配置案例 [root@master docker]# cat daemon.json { "registry-mir ...
- 《Mining of Massive Datasets》笔记(一)
数据挖掘基本概念 数据挖掘定义 最广为接受得到定义是,数据挖掘是数据"模型"的发现过程.而"模型"却可以有多种含义. 1)统计建模 统计学家认为数据挖掘就是统计 ...
- 和openjdk在一起的第一天-第一次接触有些生疏,就先熟悉一下吧
暂时搞到了openjdk7,就将就着看吧,(为什么csdn全部都是收费啊,llllj),但是还是决定先读这个openjdk7 还有,不知道怎么的就想试试markdown,也不知道好用不 hello w ...
- C#编写图书列表winform
Book.cs文件 using System; using System.Collections.Generic; using System.Linq; using System.Text; usin ...
- Django设置上传文件夹
django提供了两种字段类型models.FileField与models.ImageField,用于保存上传文件与图象.这两类字段提供了一个参数'upload_to',用于定义上传文件保存的路径( ...
- 前端基础之JavaScript_(4)_js的作用域
js作用域 作用域就是变量与函数的可访问范围,即作用域控制着变量与函数的可见性和生命周期.在JavaScript中,变量的作用域有全局作用域和局部作用域两种. js的作用域 1. 全局作用域(Glob ...
- PDO:数据访问抽象层
<?php //PDO:数据访问抽象层 //带有事务功能: //dsn:数据源 $dsn="mysql:host=localhost;dbname=aaas"; //造pdo ...
- openstack ha 部署
一.控制节点架构如下图: 二.初始化环境: 1.配置IP地址: 1.节点1:ip addr add dev eth0 192.168.142.110/24 echo 'ip addr add dev ...
- Incomplete response received from application
RAILS_ENV=production rake secret 将输出的一大串字码粘贴到rails工程中/config/secrets.yml去,替换掉该文件中的<%= ENV["S ...
- 使用新浪IP库获取IP详细地址
使用新浪IP库获取IP详细地址 <?php class Tool{ /** * 获取IP的归属地( 新浪IP库 ) * * @param $ip String IP地址:112.65.102.1 ...