0

I'm trying to resize images. It works fine, but my ImageField, which is to_field, is opening but not closing. So I have an error too many open files. I tried some work-around solutions but I wasn't able to fix the problem. Here is the code:

if( to_field.width != size[0] and to_field.height != size[1] ):
   to_field.open()
   image = Image.open(StringIO(to_field.read()))
   old_file_path = to_field.path
   image.resize(size).save(to_field.path)

Any advice??

4

1 回答 1

0

老问题,但我认为需要关闭的是 django 字段to_field :

to_field.close()
于 2016-06-07T12:19:37.797 回答