| 1 |
################################# |
| 2 |
Alternatives and related projects |
| 3 |
################################# |
| 4 |
|
| 5 |
This document presents other projects that provide similar or complementary |
| 6 |
functionalities. It focuses on differences with django-downloadview. |
| 7 |
|
| 8 |
There is a comparison grid on djangopackages.com: |
| 9 |
https://www.djangopackages.com/grids/g/file-streaming/. |
| 10 |
|
| 11 |
Here are additional highlights... |
| 12 |
|
| 13 |
|
| 14 |
************************* |
| 15 |
Django's static file view |
| 16 |
************************* |
| 17 |
|
| 18 |
`django.contrib.staticfiles provides a view to serve files`_. It is simple and |
| 19 |
quite naive by design: it is meant for development, not for production. |
| 20 |
See `Django ticket #2131`_: advanced file streaming is left to third-party |
| 21 |
applications. |
| 22 |
|
| 23 |
`django-downloadview` is such a third-party application. |
| 24 |
|
| 25 |
|
| 26 |
*************** |
| 27 |
django-sendfile |
| 28 |
*************** |
| 29 |
|
| 30 |
`django-sendfile`_ is a wrapper around web-server specific methods for sending |
| 31 |
files to web clients. |
| 32 |
|
| 33 |
.. note:: |
| 34 |
|
| 35 |
:func:`django_downloadview.shortcuts.sendfile` is a port of |
| 36 |
`django-sendfile`'s main function. See :doc:`/django-sendfile` for details. |
| 37 |
|
| 38 |
``django-senfile``'s main focus is simplicity: API is made of a single |
| 39 |
``sendfile()`` function you call inside your views: |
| 40 |
|
| 41 |
.. code:: python |
| 42 |
|
| 43 |
from sendfile import sendfile |
| 44 |
|
| 45 |
def hello_world(request): |
| 46 |
"""Send 'hello-world.pdf' file as a response.""" |
| 47 |
return sendfile(request, '/path/to/hello-world.pdf') |
| 48 |
|
| 49 |
The download response type depends on the chosen backend, which could |
| 50 |
be Django, Lighttpd's X-Sendfile, Nginx's X-Accel... depending your settings: |
| 51 |
|
| 52 |
.. code:: python |
| 53 |
|
| 54 |
SENDFILE_BACKEND = 'sendfile.backends.nginx' # sendfile() will return |
| 55 |
# X-Accel responses. |
| 56 |
# Additional settings for sendfile's nginx backend. |
| 57 |
SENDFILE_ROOT = '/path/to' |
| 58 |
SENDFILE_URL = '/proxied-download' |
| 59 |
|
| 60 |
Here are main differences between the two projects: |
| 61 |
|
| 62 |
* ``django-sendfile`` supports only files that live on local filesystem (i.e. |
| 63 |
where ``os.path.exists`` returns ``True``). Whereas ``django-downloadview`` |
| 64 |
allows you to serve or proxy files stored in various locations, including |
| 65 |
remote ones. |
| 66 |
|
| 67 |
* ``django-sendfile`` uses a single global configuration (i.e. |
| 68 |
``settings.SENDFILE_ROOT``), thus optimizations are limited to a single |
| 69 |
root folder. Whereas ``django-downloadview``'s |
| 70 |
``DownloadDispatcherMiddleware`` supports multiple configurations. |
| 71 |
|
| 72 |
|
| 73 |
.. rubric:: References |
| 74 |
|
| 75 |
.. target-notes:: |
| 76 |
|
| 77 |
.. _`django.contrib.staticfiles provides a view to serve files`: |
| 78 |
https://docs.djangoproject.com/en/3.0/ref/contrib/staticfiles/#static-file-development-view |
| 79 |
.. _`Django ticket #2131`: https://code.djangoproject.com/ticket/2131 |
| 80 |
.. _`django-sendfile`: http://pypi.python.org/pypi/django-sendfile |