文件对象

文件对象

django.core.files  模块和它的子模块包含了内置的类,基本的文件处理在Django


文件类:

文件类是一个thin封装一个Python的文件对象使用一些Django-specific

File objects have the following attributes and methods:

文件对象具有下面的属性和方法:

def handle_upload_file(file,filename):
    path='/tmp/'     #上传文件的保存路径,可以自己指定任意的路径  
    if not os.path.exists(path):
        os.makedirs(path)
    with open(path+filename,'wb+')as destination:
        for chunk in file.chunks():
            print '-----------'
            print chunk
            print '-----------'
            print '##############'
            print file.name
            print '##############'
            destination.write(chunk)
			
			
##############
mq.sh
##############

file

文件的一些子类,包含内容文件和字段文件,可能替换这个属性使用一个对象相比一个Python 文件对象。

在这些例子里,这个属性可能本身是一个File子类

mode

读/写 模式对于文件

open(mode=None)[source]

chunks(chunk_size=None)[source]¶

迭代文件 yielding 给定大小的size , chunk_size defaults to 64 KB.

这对于非常大的文件特别有用,因为它允许他们分流到磁盘,避免存储整个文件到内存

原文地址:https://www.cnblogs.com/hzcya1995/p/13349278.html