【Python】Django 支持 restful 风格 url
2016-10-21 14:53
651 查看
URL通配符示例:
代码示例:
url(r'^file_download/(?P<filename>(.)*)$', views.FILE_DOWNLOAD_VIEW.as_view()),
代码示例:
def get(self, request, filename): from common.s3_storage import S3_STORAGE s3_storage = S3_STORAGE() key = s3_storage.package_bucket.get_key(filename) assert(key is not None) import tempfile temp = tempfile.NamedTemporaryFile() try: #temp = tempfile.TemporaryFile() key.get_contents_to_filename(temp.name) temp.seek(0) c = temp.read() #c = key.get_contents_as_string() #return APIResponse(status=status_code.success, data=OS_AND_KERNEL_MAPS) from django.http import StreamingHttpResponse #response = HttpResponse(c) response = StreamingHttpResponse(c) #response = StreamingHttpResponse( self.file_iterator(temp) ) response['Content-Type'] = 'application/octet-stream' import os response['Content-Length'] = os.path.getsize(temp.name) response['Content-Disposition'] = 'attachment;filename="{0}"'.format(filename) return response finally: temp.close()
相关文章推荐
- python bottle框架支持jquery ajax的RESTful风格的PUT和DELETE方法
- 让python bottle框架支持jquery ajax的RESTful风格的PUT和DELETE等请求
- 让python bottle框架支持jquery ajax的RESTful风格的PUT和DELETE等请求(新方法)
- Python的Django框架中的URL配置与松耦合
- 使用python创建一个简单的restful风格的webservice应用
- python cherrypy RESTful API,cherrypy支持跨域ajax访问,CROS,crossdomain ajax
- Python(8)——Django之URL配置
- django+httpd+mod_pythonurl存在中文路径问题解决
- django如何使用restful风格
- Python+Django+SAE系列教程9-----Django的视图和URL
- 用python创建一个简单的restful风格的web服务应用
- 使用url_helper简化Python中Django框架的url配置教程
- python下的web开发框架-Django,url配置
- 使用url_helper简化Python中Django框架的url配置教程
- django中url,静态文件,POST请求的配置 分类: Python 2015-06-01 17:00 789人阅读 评论(0) 收藏
- 改写Restful2ActionMapper让Struts2支持REST风格的URL映射
- PYTHON(DJANGO)使用日记之如何改变admin控制下的页面风格
- django1.4.1 最高支持的python 版本
- Python系列视频教程: Django【13讲】第五讲 URL配置
- Python---django 带参数的 url