Debian Codegraph @

docs/settings.txt

raw
1 #########
2 Configure
3 #########
4
5 Here is the list of Django settings for `django-downloadview`.
6
7
8 **************
9 INSTALLED_APPS
10 **************
11
12 There is no need to register this application in ``INSTALLED_APPS``.
13
14
15 ******************
16 MIDDLEWARE
17 ******************
18
19 If you plan to setup :doc:`reverse-proxy optimizations </optimizations/index>`,
20 add ``django_downloadview.SmartDownloadMiddleware`` to ``MIDDLEWARE``.
21 It is a response middleware. Move it after middlewares that compute the
22 response content such as gzip middleware.
23
24 Example:
25
26 .. literalinclude:: /../demo/demoproject/settings.py
27 :language: python
28 :start-after: BEGIN middlewares
29 :end-before: END middlewares
30
31
32 ********************
33 DEFAULT_FILE_STORAGE
34 ********************
35
36 django-downloadview offers a built-in signed file storage, which cryptographically
37 signs requested file URLs with the Django's built-in TimeStampSigner.
38
39 To utilize the signed storage views you can configure
40
41 .. code:: python
42
43 DEFAULT_FILE_STORAGE='django_downloadview.storage.SignedStorage'
44
45 The signed file storage system inserts a ``X-Signature`` header to the requested file
46 URLs, and they can then be verified with the supplied ``signature_required`` wrapper function:
47
48 .. code:: python
49
50 from django.conf.urls import url, url_patterns
51
52 from django_downloadview import ObjectDownloadView
53 from django_downloadview.decorators import signature_required
54
55 from demoproject.download.models import Document # A model with a FileField
56
57 # ObjectDownloadView inherits from django.views.generic.BaseDetailView.
58 download = ObjectDownloadView.as_view(model=Document, file_field='file')
59
60 urlpatterns = [
61 path('download/<str:slug>/', signature_required(download)),
62 ]
63
64 Make sure to test the desired functionality after configuration.
65
66 ***************************
67 DOWNLOADVIEW_URL_EXPIRATION
68 ***************************
69
70 Number of seconds signed download URLs are valid before expiring.
71
72 Default value for this flag is None and URLs never expire.
73
74 ********************
75 DOWNLOADVIEW_BACKEND
76 ********************
77
78 This setting is used by
79 :class:`~django_downloadview.middlewares.SmartDownloadMiddleware`.
80 It is the import string of a callable (typically a class) of an optimization
81 backend (typically a :class:`~django_downloadview.BaseDownloadMiddleware`
82 subclass).
83
84 Example:
85
86 .. literalinclude:: /../demo/demoproject/settings.py
87 :language: python
88 :start-after: BEGIN backend
89 :end-before: END backend
90
91 See :doc:`/optimizations/index` for a list of available backends (middlewares).
92
93 When ``django_downloadview.SmartDownloadMiddleware`` is in your
94 ``MIDDLEWARE``, this setting must be explicitely configured (no default
95 value). Else, you can ignore this setting.
96
97
98 ******************
99 DOWNLOADVIEW_RULES
100 ******************
101
102 This setting is used by
103 :class:`~django_downloadview.middlewares.SmartDownloadMiddleware`.
104 It is a list of positional arguments or keyword arguments that will be used to
105 instanciate class mentioned as ``DOWNLOADVIEW_BACKEND``.
106
107 Each item in the list can be either a list of positional arguments, or a
108 dictionary of keyword arguments. One item cannot contain both positional and
109 keyword arguments.
110
111 Here is an example containing one rule using keyword arguments:
112
113 .. literalinclude:: /../demo/demoproject/settings.py
114 :language: python
115 :start-after: BEGIN rules
116 :end-before: END rules
117
118 See :doc:`/optimizations/index` for details about builtin backends
119 (middlewares) and their options.
120
121 When ``django_downloadview.SmartDownloadMiddleware`` is in your
122 ``MIDDLEWARE``, this setting must be explicitely configured (no default
123 value). Else, you can ignore this setting.