django_sendfile.utils module

django_sendfile.utils.sendfile(request, filename, attachment=False, attachment_filename=None, mimetype=None, encoding=None)[source]

Create a response to send file using backend configured in SENDFILE_BACKEND

filename is the absolute path to the file to send.

If attachment is True the Content-Disposition header will be set accordingly. This will typically prompt the user to download the file, rather than view it. But even if False, the user may still be prompted, depending on the browser capabilities and configuration.

The Content-Disposition filename depends on the value of attachment_filename:

None (default): Same as filename False: No Content-Disposition filename String: Value used as filename

If neither mimetype or encoding are specified, then they will be guessed via the filename (using the standard Python mimetypes module)