Flask download file vs django download file
2016-03-17 16:08
746 查看
Only difference is make_response and httpresponse.
FLASK VERSION:
Django Version:
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
相关文章推荐
- django的restfulapi
- 二、slice和数组的区别,map的注意事项 -go语言笔记
- Mongo在存储大量数据时,有数据存储不上的情况?
- Mongo在存储大量数据时,有数据存储不上的情况?
- google log 使用
- go语言select关注点
- 人机大战之AlphaGo的硬件配置和算法研究
- A Fast Single Image Haze Removal Algorithm Using Color Attenuation Prior——基于颜色衰减先验单图片去雾算法原理
- Django--ajax
- 深度学习工程师:为什么AlphaGo难取胜?这是在取胜之前说的。
- go语言数组的拷贝
- Django session 详解
- ongodb内存管理和使用情况情况查询
- Django配置Session的3种存储方法
- Gonsion携手3M触控推出2K和4K多点触摸屏显示器(32寸,42寸,46寸,55寸,65寸)C2137PW | C3237PW | C4237PW | C4637PW | C 5537PW |C
- Google自己的下拉刷新组件SwipeRefreshLayout
- 使用GDI+绘制的360风格按钮控件(使用CN_DRAWITEM消息重绘,并使用TGPGraphics,TGPPen,TGPImage,TGPBitmap等)good
- Go初探
- 遗传算法Genetic Algorithm
- 编写GO的WEB开发框架 (十三): 配置文件读取