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 に答える