mirror of
https://github.com/jazzband/django-downloadview.git
synced 2026-05-24 07:03:49 +00:00
103 lines
3.5 KiB
Text
103 lines
3.5 KiB
Text
#################################
|
|
Alternatives and related projects
|
|
#################################
|
|
|
|
This document presents other projects that provide similar or complementary
|
|
functionalities. It focuses on differences with django-downloadview.
|
|
|
|
|
|
*************************
|
|
Django's static file view
|
|
*************************
|
|
|
|
`Django has a builtin static file view`_. It can stream files. As explained in
|
|
Django documentation, it is designed for development purposes. For production,
|
|
static files'd better be served by some optimized server.
|
|
|
|
Django-downloadview can replace Django's builtin static file view:
|
|
|
|
* perform actions with Django when receiving download requests: check
|
|
permissions, generate files, gzip, logging, signals...
|
|
* delegate actual download to a reverse proxy for increased performance.
|
|
* disable optimization middlewares or decorators in development, if you want to
|
|
serve files with Django.
|
|
|
|
|
|
***************
|
|
django-sendfile
|
|
***************
|
|
|
|
`django-sendfile`_ is a wrapper around web-server specific methods for sending
|
|
files to web clients.
|
|
|
|
``django-senfile``'s main focus is simplicity: API is made of a single
|
|
``sendfile()`` function you call inside your views:
|
|
|
|
.. code:: python
|
|
|
|
from sendfile import sendfile
|
|
|
|
def hello_world(request):
|
|
"""Send 'hello-world.pdf' file as a response."""
|
|
return sendfile(request, '/path/to/hello-world.pdf')
|
|
|
|
The download response type depends on the chosen backend, which could
|
|
be Django, Lighttpd's X-Sendfile, Nginx's X-Accel... depending your settings:
|
|
|
|
.. code:: python
|
|
|
|
SENDFILE_BACKEND = 'sendfile.backends.nginx' # sendfile() will return
|
|
# X-Accel responses.
|
|
# Additional settings for sendfile's nginx backend.
|
|
SENDFILE_ROOT = '/path/to'
|
|
SENDFILE_URL = '/proxied-download'
|
|
|
|
Here are main differences between the two projects:
|
|
|
|
* ``django-sendfile`` supports only files that live on local filesystem (i.e.
|
|
where ``os.path.exists`` returns ``True``). Whereas ``django-downloadview``
|
|
allows you to serve or proxy files stored in various locations, including
|
|
remote ones.
|
|
|
|
* ``django-sendfile`` uses a single global configuration (i.e.
|
|
``settings.SENDFILE_ROOT``), thus optimizations are limited to a single
|
|
root folder. Whereas ``django-downloadview``'s
|
|
``DownloadDispatcherMiddleware`` supports multiple configurations.
|
|
|
|
As of 2012-04-11, ``django-sendfile`` (version 0.3.2) seems quite popular and
|
|
may be a good alternative **provided you serve files that live in a single
|
|
directory of local filesystem**.
|
|
|
|
:func:`django_downloadview.sendfile` is a port of django-sendfile's main function.
|
|
|
|
|
|
********************
|
|
django-private-files
|
|
********************
|
|
|
|
`django-private-files`_ provides utilities for controlling access to static
|
|
files based on conditions you can specify within your Django application.
|
|
|
|
|
|
**********************
|
|
django-protected-files
|
|
**********************
|
|
|
|
`django-protected-files`_ is a Django application that lets you serve protected
|
|
static files via your frontend server after authorizing the user against
|
|
``django.contrib.auth``.
|
|
|
|
As of 2012-12-10, this project seems inactive.
|
|
|
|
|
|
.. rubric:: References
|
|
|
|
.. target-notes::
|
|
|
|
.. _`Django has a builtin static file view`:
|
|
https://docs.djangoproject.com/en/1.4/ref/contrib/staticfiles/#static-file-development-view
|
|
.. _`django-sendfile`: http://pypi.python.org/pypi/django-sendfile
|
|
.. _`requests`: https://pypi.python.org/pypi/requests
|
|
.. _`django-private-files`: http://pypi.python.org/pypi/django-private-files
|
|
.. _`django-protected-files`:
|
|
https://github.com/lincolnloop/django-protected-files
|