File wrappers

A view return DownloadResponse which itself carries a file wrapper. Here are file wrappers distributed by Django and django-downloadview.

Django’s builtins

Django itself provides some file wrappers [1] you can use within django-downloadview:

django-downloadview builtins

django-downloadview implements additional file wrappers:

  • StorageFile wraps a file that is managed via a storage (but not necessarily via a model). StorageDownloadView uses this wrapper.
  • HTTPFile wraps a file that lives at some (remote) location, initialized with an URL. HTTPDownloadView uses this wrapper.
  • VirtualFile wraps a file that lives in memory, i.e. built as a string. This is a convenient wrapper to use in VirtualDownloadView subclasses.

Low-level IO utilities

django-downloadview provides two classes to implement file-like objects whose content is dynamically generated:

  • TextIteratorIO for generated text;
  • BytesIteratorIO for generated bytes.

These classes may be handy to serve dynamically generated files. See VirtualDownloadView for details.


Text or bytes? (formerly “unicode or str?”) As django-downloadview is meant to serve files, as opposed to read or parse files, what matters is file contents is preserved. django-downloadview tends to handle files in binary mode and as bytes.

API reference