Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR PYTHON

python - "Upload" a file from django shell

from django.core.files import File

f = File(open(os.path.join(IMPORT_DIR, 'fotos', photo), 'rb'))
p = Photo(name=f.name, image=f, parent=supply.supply_ptr)
name = str(uuid1()) + os.path.splitext(f.name)[1]
p.image.save(name, f)
p.save()
Source by pythonhowto.org #
 
PREVIOUS NEXT
Tagged: #python #file #django #shell
ADD COMMENT
Topic
Name
3+2 =