Responses

Views return DownloadResponse.

Middlewares (and decorators) are given the opportunity to capture responses and convert them to ProxiedDownloadResponse.

DownloadResponse

class django_downloadview.response.DownloadResponse(file_instance, attachment=True, basename=None, status=200, content_type=None)

Bases: django.http.response.StreamingHttpResponse

File download response (Django serves file, client downloads it).

This is a specialization of django.http.StreamingHttpResponse where streaming_content is a file wrapper.

Constructor differs a bit from HttpResponse:

file_instance
A file wrapper instance, such as File.
attachement
Boolean. Whether to return the file as attachment or not. Affects Content-Disposition header.
basename
Unicode. Client-side name of the file to stream. Only used if attachment is True. Affects Content-Disposition header.
status
HTTP status code.
content_type
Value for Content-Type header. If None, then mime-type and encoding will be populated by the response (default implementation uses mimetypes, based on file name).

Here are some highlights to understand internal mechanisms and motivations:

default_headers

Return dictionary of automatically-computed headers.

Uses an internal _default_headers cache. Default values are computed if only cache hasn’t been set.

items()

Return iterable of (header, value).

This method is called by http handlers just before WSGI’s start_response() is called... but it is not called by django.test.ClientHandler! :’(

get_basename()

Return basename.

get_content_type()

Return a suitable “Content-Type” header for self.file.

get_mime_type()

Return mime-type of the file.

get_encoding()

Return encoding of the file to serve.

get_charset()

Return the charset of the file to serve.

ProxiedDownloadResponse

class django_downloadview.response.ProxiedDownloadResponse(content='', *args, **kwargs)

Bases: django.http.response.HttpResponse

Base class for internal redirect download responses.

This base class makes it possible to identify several types of specific responses such as XAccelRedirectResponse.

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.