Overview, concepts

Given:

  • you manage files with Django (permissions, search, generation, ...)
  • files are stored somewhere or generated somehow (local filesystem, remote storage, memory...)

As a developer, you want to serve files quick and efficiently.

Here is an overview of django-downloadview‘s answer...

Generic views cover commons patterns

Choose the generic view depending on the file you want to serve:

Generic views and mixins allow easy customization

If your use case is a bit specific, you can easily extend the views above or create your own based on mixins.

Views return DownloadResponse

Views return DownloadResponse. It is a special django.http.StreamingHttpResponse where content is encapsulated in a file wrapper.

Learn more in Responses.

DownloadResponse carry file wrapper

Views instanciate a file wrapper and use it to initialize responses.

File wrappers describe files: they carry files properties such as name, size, encoding...

File wrappers implement loading and iterating over file content. Whenever possible, file wrappers do not embed file data, in order to save memory.

Learn more about available file wrappers in File wrappers.

Middlewares convert DownloadResponse into ProxiedDownloadResponse

Before WSGI application use file wrapper to load file contents, middlewares (or decorators) are given the opportunity to capture DownloadResponse instances.

Let’s take this opportunity to optimize file loading and streaming!

A good optimization it to delegate streaming to a reverse proxy, such as nginx [1] via X-Accel [2] internal redirects.

django_downloadview provides middlewares that convert DownloadResponse into ProxiedDownloadResponse.

Learn more in Optimize streaming.

Testing matters

django-downloadview also helps you test the views you customized.

You may also write healthchecks to make sure everything goes fine in live environments.

Read the Docs v: 1.3
Versions
latest
1.3
1.2
1.1
1.0
Downloads
On Read the Docs
Project Home
Builds

Free document hosting provided by Read the Docs.