2012-08-27 10:00:17 +00:00
|
|
|
###################
|
2013-02-06 17:59:22 +00:00
|
|
|
django-downloadview
|
2012-08-27 10:00:17 +00:00
|
|
|
###################
|
|
|
|
|
|
2013-10-04 16:11:16 +00:00
|
|
|
`django-downloadview` makes it easy to serve files with Django.
|
2012-08-27 10:00:17 +00:00
|
|
|
|
2013-10-04 16:11:16 +00:00
|
|
|
It provides generic views to serve files from models, storages, local
|
|
|
|
|
filesystem, arbitrary URL... and even generated files.
|
2013-04-11 13:42:28 +00:00
|
|
|
|
|
|
|
|
For increased performances, it can delegate the actual streaming to a reverse
|
|
|
|
|
proxy, via mechanisms such as Nginx's X-Accel.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
*******
|
|
|
|
|
Example
|
|
|
|
|
*******
|
|
|
|
|
|
2013-05-28 12:40:46 +00:00
|
|
|
In some ``urls.py``, serve files managed in a model:
|
2012-08-27 10:00:17 +00:00
|
|
|
|
2012-08-27 15:25:24 +00:00
|
|
|
.. code-block:: python
|
|
|
|
|
|
|
|
|
|
from django.conf.urls import url, url_patterns
|
|
|
|
|
from django_downloadview import ObjectDownloadView
|
2012-12-10 10:05:28 +00:00
|
|
|
from demoproject.download.models import Document # A model with a FileField
|
2012-08-27 15:25:24 +00:00
|
|
|
|
2012-08-27 15:33:33 +00:00
|
|
|
# ObjectDownloadView inherits from django.views.generic.BaseDetailView.
|
|
|
|
|
download = ObjectDownloadView.as_view(model=Document, file_field='file')
|
2012-08-27 15:25:24 +00:00
|
|
|
|
|
|
|
|
url_patterns = ('',
|
2012-08-27 15:33:33 +00:00
|
|
|
url('^download/(?P<slug>[A-Za-z0-9_-]+)/$', download, name='download'),
|
2012-08-27 15:25:24 +00:00
|
|
|
)
|
2013-02-06 15:18:37 +00:00
|
|
|
|
2013-05-28 12:40:46 +00:00
|
|
|
More examples in the "demo" documentation!
|
2013-04-11 13:42:28 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
*****
|
|
|
|
|
Views
|
|
|
|
|
*****
|
|
|
|
|
|
2013-02-06 15:18:37 +00:00
|
|
|
Several views are provided to cover frequent use cases:
|
|
|
|
|
|
|
|
|
|
* ``ObjectDownloadView`` when you have a model with a file field.
|
2013-02-06 17:59:22 +00:00
|
|
|
* ``StorageDownloadView`` when you manage files in a storage.
|
|
|
|
|
* ``PathDownloadView`` when you have an absolute filename on local filesystem.
|
2013-05-28 06:34:33 +00:00
|
|
|
* ``HTTPDownloadView`` when you have an URL (the resource is proxied).
|
2013-02-06 19:11:42 +00:00
|
|
|
* ``VirtualDownloadView`` when you the file is generated on the fly.
|
2013-02-06 15:18:37 +00:00
|
|
|
|
2013-05-28 12:40:46 +00:00
|
|
|
See "views" documentation for details.
|
|
|
|
|
|
|
|
|
|
See also "optimizations" documentation to get increased performances.
|
2013-02-06 15:18:37 +00:00
|
|
|
|
2012-08-27 10:00:17 +00:00
|
|
|
|
|
|
|
|
**********
|
|
|
|
|
Ressources
|
|
|
|
|
**********
|
|
|
|
|
|
2013-03-20 15:27:58 +00:00
|
|
|
* Documentation: http://django-downloadview.readthedocs.org
|
2012-08-27 10:00:17 +00:00
|
|
|
* PyPI page: http://pypi.python.org/pypi/django-downloadview
|
2013-03-20 15:27:58 +00:00
|
|
|
* Code repository: https://github.com/benoitbryon/django-downloadview
|
|
|
|
|
* Bugtracker: https://github.com/benoitbryon/django-downloadview/issues
|
|
|
|
|
* Continuous integration: https://travis-ci.org/benoitbryon/django-downloadview
|