升级到Django 1.0后,原来的文件上传程序不能运行,报告了下列错误:
[2008-09-17 Wed 10:20:52]ERROR "<type 'exceptions.TypeError'>
'InMemoryUploadedFile' object is unsubscriptable
[('/home/dev2/deploy/divo3/apps/xf/views/check_report_content.py', 297, 'add_system1_pic', "fd.write(file['content'])")]"
原来的上传程序如下:
file = request.FILES['file']
file_name = get_unique_file_name() #生成唯一的文件名
path1 = os.path.join(settings.DIVO_TEMP_ROOT, 'xf')
fd = open('%s/%s' % (path1, file_name), 'wb')
fd.write(file['content'])
fd.close()
现在修改为:
file = request.FILES['file']
file_name = get_unique_file_name()
path1 = os.path.join(settings.DIVO_TEMP_ROOT, 'xf')
destination = open('%s/%s' % (path1, file_name), 'wb+')
for chunk in file.chunks():
destination.write(chunk)
destination.close()
从上面的新程序中可以看出,Django解决了大文件上传时的内存占用问题。
分享到:
相关推荐
django 1.0官方的使用文档chm打包
Django1.0速查手册,Django 1.0 Cheat sheet
Django1.0以上版本的教材-DjangoBook2.0中文版.pdf 适用于Django1.0以上的环境
Django1.0 手册 CHM格式 英文的
Django 1.0 中文文档.docDjango 1.0 中文文档.docDjango 1.0 中文文档.docDjango 1.0 中文文档.doc
Django 1.0 Template Development
Django 1.0 Cheat Sheet 非常好的东西。
NULL 博文链接:https://woods.iteye.com/blog/299722
Django 1.0 Template Development – Free Pdf Book
python web开发的框架最新版本1.0.这是一个快速的开发框架。放在这里方便大家下载。
django book 1.0 中文 主要是附录部分有用
Chapter 1: Introduction to Django 7 MVC pattern in web development 7 Why Python? 8 Why Django? 9 Tight integration between components 10 Object-Relational Mapper 10 Clean URL design 10 ...
emphasizes utilizing Django and Python to create a Web 2.0 bookmark-sharing application, with many common features found in the Web 2.0 sites these days. The book follows a tutorial style to introduce...
A practical guide to Django template development with custom tags, filters, multiple templates, caching, and more Scott Newman
Django的1.0文档chm版本,本来也有cheetsheet版本的,可以之后传上来。 1.0的文档变化很大,大家不妨仔细看看。
django手册的中英文对照翻译!django手册的中英文对照翻译!django手册的中英文对照翻译!
使用Django实现的文件分享系统,实现搜索功能,分享功能,用户分享文件查询,写该项目的目的主要是用于保存一些电子书籍和学习资料,方便自己和其他人查找资料,所以对文件大小进行限制最大为5M。 使用Django...
基于Python+Django简单实现文件上传下载功能源码 基于Python+Django简单实现文件上传下载功能源码 基于Python+Django简单实现文件上传下载功能源码 基于Python+Django简单实现文件上传下载功能源码 基于...
This archive includes documentations shipped with Django1.1 release. However the doc version reads 1.0...................
Django book 1.0, Django book 2.0 美化合并版, 版权归属 http://djangobook.py3k.cn/, 美化合并 by Rogues, http://rogues.download.csdn.net/ 下载正版! Django book 2.0 中文版 第一章:介紹Django 第二章:...