DEV/Django

[Django] ValueError: I/O operation in closed file

뚜비두빱 2022. 5. 15. 23:40

ValueError: I/O operation in closed file

 

장고의 imageField를 open하고 다시 같은 파일을 open하려고 할때 나는 오류입니다.

stackoverflow에서 아래와 같은 코멘트가 있었습니다.

"imageField.open() doesn't alter the file's contents, but it does reset the pointer”

 

따라서 image를 두번 오픈할 때

copy.deepcopy(깊은복사) 로 image를 복사해준 후 open해주면 오류가 나지 않았습니다.

  • 깊은 복사는 내부에 객체들까지 모두 새롭게 copy 되는 것입니다.