[Django]-Does Django close and delete TemporaryUploadedFiles and InMemoryUploadedFiles?

3👍

These files are closed, WSGI handler can provide a method called close and that method is called post-processing of the request.

Django source code (http/request.py)

class HttpRequest:
  ...
  def close(self):
     if hasattr(self, '_files'):
        for f in chain.from_iterable(list_[1] for list_ in self._files.lists()):
           f.close()

Edit:

Django globally configures two types of file uploader InMemory and Temp file. All these classes implement theclose method, the close method of request object is registered as _resource_closers and these methods are called from HttpResponseBase‘s close method.

Leave a comment