django-sendfile[3] 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:
fromsendfileimportsendfiledefhello_world(request):"""Send 'hello-world.pdf' file as a response."""returnsendfile(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:
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.
django_downloadview.sendfile() is a port of django-sendfile’s main function.