|
2 | 2 |
|
3 | 3 | <p class="intro" markdown>
|
4 | 4 |
|
5 |
| -<!--intro-start--> |
6 |
| - |
7 | 5 | These are ReactPy-Django's default settings values. You can modify these values in your **Django project's** `settings.py` to change the behavior of ReactPy.
|
8 | 6 |
|
9 |
| -<!--intro-end--> |
10 |
| - |
11 | 7 | </p>
|
12 | 8 |
|
13 |
| -!!! note |
| 9 | +!!! abstract "Note" |
14 | 10 |
|
15 | 11 | The default configuration of ReactPy is suitable for the vast majority of use cases.
|
16 | 12 |
|
17 | 13 | You should only consider changing settings when the necessity arises.
|
18 | 14 |
|
19 | 15 | ---
|
20 | 16 |
|
21 |
| -<!--config-table-start--> |
22 |
| - |
23 | 17 | ## General Settings
|
24 | 18 |
|
25 |
| -| Setting | Default Value | Example Value(s) | Description | |
26 |
| -| --- | --- | --- | --- | |
27 |
| -| `#!python REACTPY_URL_PREFIX` | `#!python "reactpy/"` | `#!python "rp/"`, `#!python "render/reactpy/"` | The prefix used for all ReactPy WebSocket and HTTP URLs. | |
28 |
| -| `#!python REACTPY_DEFAULT_QUERY_POSTPROCESSOR` | `#!python "reactpy_django.utils.django_query_postprocessor"` | `#!python "example_project.postprocessor"`, `#!python None` | Dotted path to the default `#!python reactpy_django.hooks.use_query` postprocessor function. Postprocessor functions can be async or sync, and the function must contain a `#!python data` parameter. Set `#!python REACTPY_DEFAULT_QUERY_POSTPROCESSOR` to `#!python None` to globally disable the default postprocessor. | |
29 |
| -| `#!python REACTPY_AUTH_BACKEND` | `#!python "django.contrib.auth.backends.ModelBackend"` | `#!python "example_project.auth.MyModelBackend"` | Dotted path to the Django authentication backend to use for ReactPy components. This is only needed if:<br/> 1. You are using `#!python AuthMiddlewareStack` and...<br/> 2. You are using Django's `#!python AUTHENTICATION_BACKENDS` setting and...<br/> 3. Your Django user model does not define a `#!python backend` attribute. | |
| 19 | +--- |
| 20 | + |
| 21 | +### `#!python REACTPY_URL_PREFIX` |
| 22 | + |
| 23 | +**Default:** `#!python "reactpy/"` |
| 24 | + |
| 25 | +**Example Value(s):** `#!python "rp/"`, `#!python "render/reactpy/"` |
| 26 | + |
| 27 | +The prefix used for all ReactPy WebSocket and HTTP URLs. |
| 28 | + |
| 29 | +--- |
| 30 | + |
| 31 | +### `#!python REACTPY_DEFAULT_QUERY_POSTPROCESSOR` |
| 32 | + |
| 33 | +**Default:** `#!python "reactpy_django.utils.django_query_postprocessor"` |
| 34 | + |
| 35 | +**Example Value(s):** `#!python "example_project.postprocessor"`, `#!python None` |
| 36 | + |
| 37 | +Dotted path to the default `#!python reactpy_django.hooks.use_query` postprocessor function. |
| 38 | + |
| 39 | +Postprocessor functions can be async or sync. Here is an example of a sync postprocessor function: |
| 40 | + |
| 41 | +```python linenums="0" |
| 42 | +def postprocessor(data): |
| 43 | + del data["foo"] |
| 44 | + return data |
| 45 | +``` |
| 46 | + |
| 47 | +Set `#!python REACTPY_DEFAULT_QUERY_POSTPROCESSOR` to `#!python None` to disable the default postprocessor. |
| 48 | + |
| 49 | +--- |
| 50 | + |
| 51 | +### `#!python REACTPY_AUTH_BACKEND` |
| 52 | + |
| 53 | +**Default:** `#!python "django.contrib.auth.backends.ModelBackend"` |
| 54 | + |
| 55 | +**Example Value(s):** `#!python "example_project.auth.MyModelBackend"` |
| 56 | + |
| 57 | +Dotted path to the Django authentication backend to use for ReactPy components. This is only needed if: |
| 58 | + |
| 59 | +1. You are using `#!python AuthMiddlewareStack` and... |
| 60 | +2. You are using Django's `#!python AUTHENTICATION_BACKENDS` setting and... |
| 61 | +3. Your Django user model does not define a `#!python backend` attribute. |
| 62 | + |
| 63 | +--- |
30 | 64 |
|
31 | 65 | ## Performance Settings
|
32 | 66 |
|
33 |
| -| Setting | Default Value | Example Value(s) | Description | |
34 |
| -| --- | --- | --- | --- | |
35 |
| -| `#!python REACTPY_DATABASE` | `#!python "default"` | `#!python "my-reactpy-database"` | Multiprocessing-safe database used to store ReactPy session data. If configuring `#!python REACTPY_DATABASE`, it is mandatory to enable our database router like such:<br/>`#!python DATABASE_ROUTERS = ["reactpy_django.database.Router", ...]` | |
36 |
| -| `#!python REACTPY_CACHE` | `#!python "default"` | `#!python "my-reactpy-cache"` | Cache used for ReactPy JavaScript modules. We recommend installing [`redis`](https://redis.io/) or [`python-diskcache`](https://grantjenks.com/docs/diskcache/tutorial.html#djangocache). | |
37 |
| -| `#!python REACTPY_BACKHAUL_THREAD` | `#!python False` | `#!python True` | Configures whether ReactPy components are rendered in a dedicated thread. This allows the web server to process traffic during ReactPy rendering. Vastly improves throughput with web servers such as [`hypercorn`](https://pgjones.gitlab.io/hypercorn/) and [`uvicorn`](https://www.uvicorn.org/). | |
38 |
| -| `#!python REACTPY_DEFAULT_HOSTS` | `#!python None` | `#!python ["localhost:8000", "localhost:8001", "localhost:8002/subdir"]` | The default host(s) that can render your ReactPy components. ReactPy will use these hosts in a round-robin fashion, allowing for easy distributed computing. You can use the `#!python host` argument in your [template tag](../reference/template-tag.md#component) as a manual override. | |
39 |
| -| `#!python REACTPY_PRERENDER` | `#!python False` | `#!python True` | Configures whether to pre-render your components, which enables SEO compatibility and increases perceived responsiveness. You can use the `#!python prerender` argument in your [template tag](../reference/template-tag.md#component) as a manual override. During pre-rendering, there are some key differences in behavior:<br/> 1. Only the component's first render is pre-rendered.<br/> 2. All `#!python connection` related hooks use HTTP.<br/> 3. `#!python html.script` is executed during both pre-render and render.<br/> 4. Component is non-interactive until a WebSocket connection is formed. | |
| 67 | +--- |
| 68 | + |
| 69 | +### `#!python REACTPY_DATABASE` |
| 70 | + |
| 71 | +**Default:** `#!python "default"` |
| 72 | + |
| 73 | +**Example Value(s):** `#!python "my-reactpy-database"` |
| 74 | + |
| 75 | +Multiprocessing-safe database used by ReactPy, typically for session data. |
| 76 | + |
| 77 | +If configuring this value, it is mandatory to enable our database router like such: |
| 78 | + |
| 79 | +```python linenums="0" |
| 80 | +DATABASE_ROUTERS = ["reactpy_django.database.Router", ...] |
| 81 | +``` |
| 82 | + |
| 83 | +--- |
| 84 | + |
| 85 | +### `#!python REACTPY_CACHE` |
| 86 | + |
| 87 | +**Default:** `#!python "default"` |
| 88 | + |
| 89 | +**Example Value(s):** `#!python "my-reactpy-cache"` |
| 90 | + |
| 91 | +Cache used by ReactPy, typically for file operations. |
| 92 | + |
| 93 | +We recommend configuring [`redis`](https://docs.djangoproject.com/en/dev/topics/cache/#redis), [`python-diskcache`](https://grantjenks.com/docs/diskcache/tutorial.html#djangocache), or [`LocMemCache`](https://docs.djangoproject.com/en/dev/topics/cache/#local-memory-caching). |
| 94 | + |
| 95 | +--- |
| 96 | + |
| 97 | +### `#!python REACTPY_BACKHAUL_THREAD` |
| 98 | + |
| 99 | +**Default:** `#!python False` |
| 100 | + |
| 101 | +**Example Value(s):** `#!python True` |
| 102 | + |
| 103 | +Configures whether ReactPy components are rendered in a dedicated thread. |
| 104 | + |
| 105 | +This setting allows the web server to process other traffic during ReactPy rendering. Vastly improves throughput with web servers such as [`hypercorn`](https://pgjones.gitlab.io/hypercorn/) and [`uvicorn`](https://www.uvicorn.org/). |
| 106 | + |
| 107 | +--- |
| 108 | + |
| 109 | +### `#!python REACTPY_DEFAULT_HOSTS` |
| 110 | + |
| 111 | +**Default:** `#!python None` |
| 112 | + |
| 113 | +**Example Value(s):** `#!python ["localhost:8000", "localhost:8001", "localhost:8002/subdir"]` |
| 114 | + |
| 115 | +The default host(s) that can render your ReactPy components. |
| 116 | + |
| 117 | +ReactPy will use these hosts in a round-robin fashion, allowing for easy distributed computing. |
| 118 | + |
| 119 | +You can use the `#!python host` argument in your [template tag](../reference/template-tag.md#component) to manually override this default. |
| 120 | + |
| 121 | +--- |
| 122 | + |
| 123 | +### `#!python REACTPY_PRERENDER` |
| 124 | + |
| 125 | +**Default:** `#!python False` |
| 126 | + |
| 127 | +**Example Value(s):** `#!python True` |
| 128 | + |
| 129 | +Configures whether to pre-render your components, which enables SEO compatibility and reduces perceived latency. |
| 130 | + |
| 131 | +During pre-rendering, there are some key differences in behavior: |
| 132 | + |
| 133 | +1. Only the component's first render is pre-rendered. |
| 134 | +2. All `#!python connection` related hooks use HTTP. |
| 135 | +3. `#!python html.script` elements are executed twice (pre-render and post-render). |
| 136 | +4. The component will be non-interactive until a WebSocket connection is formed. |
| 137 | + |
| 138 | +You can use the `#!python prerender` argument in your [template tag](../reference/template-tag.md#component) to manually override this default. |
| 139 | + |
| 140 | +--- |
40 | 141 |
|
41 | 142 | ## Stability Settings
|
42 | 143 |
|
43 |
| -| Setting | Default Value | Example Value(s) | Description | |
44 |
| -| --- | --- | --- | --- | |
45 |
| -| `#!python REACTPY_RECONNECT_INTERVAL` | `#!python 750` | `#!python 100`, `#!python 2500`, `#!python 6000` | Milliseconds between client reconnection attempts. | |
46 |
| -| `#!python REACTPY_RECONNECT_BACKOFF_MULTIPLIER` | `#!python 1.25` | `#!python 1`, `#!python 1.5`, `#!python 3` | On each reconnection attempt, the `#!python REACTPY_RECONNECT_INTERVAL` will be multiplied by this value to increase the time between attempts. You can keep time between each reconnection the same by setting this to `#!python 1`. | |
47 |
| -| `#!python REACTPY_RECONNECT_MAX_INTERVAL` | `#!python 60000` | `#!python 10000`, `#!python 25000`, `#!python 900000` | Maximum milliseconds between client reconnection attempts. This allows setting an upper bound on how high `#!python REACTPY_RECONNECT_BACKOFF_MULTIPLIER` can increase the time between reconnection attempts. | |
48 |
| -| `#!python REACTPY_RECONNECT_MAX_RETRIES` | `#!python 150` | `#!python 0`, `#!python 5`, `#!python 300` | Maximum number of reconnection attempts before the client gives up. | |
49 |
| -| `#!python REACTPY_SESSION_MAX_AGE` | `#!python 259200` | `#!python 0`, `#!python 60`, `#!python 96000` | Maximum seconds to store ReactPy component sessions. This includes data such as `#!python *args` and `#!python **kwargs` passed into your component template tag. Use `#!python 0` to not store any session data. | |
| 144 | +--- |
| 145 | + |
| 146 | +### `#!python REACTPY_RECONNECT_INTERVAL` |
| 147 | + |
| 148 | +**Default:** `#!python 750` |
| 149 | + |
| 150 | +**Example Value(s):** `#!python 100`, `#!python 2500`, `#!python 6000` |
| 151 | + |
| 152 | +Milliseconds between client reconnection attempts. |
| 153 | + |
| 154 | +--- |
| 155 | + |
| 156 | +### `#!python REACTPY_RECONNECT_BACKOFF_MULTIPLIER` |
| 157 | + |
| 158 | +**Default:** `#!python 1.25` |
| 159 | + |
| 160 | +**Example Value(s):** `#!python 1`, `#!python 1.5`, `#!python 3` |
| 161 | + |
| 162 | +On each reconnection attempt, the `#!python REACTPY_RECONNECT_INTERVAL` will be multiplied by this value to increase the time between attempts. |
| 163 | + |
| 164 | +You can keep time between each reconnection the same by setting this to `#!python 1`. |
| 165 | + |
| 166 | +--- |
| 167 | + |
| 168 | +### `#!python REACTPY_RECONNECT_MAX_INTERVAL` |
| 169 | + |
| 170 | +**Default:** `#!python 60000` |
| 171 | + |
| 172 | +**Example Value(s):** `#!python 10000`, `#!python 25000`, `#!python 900000` |
| 173 | + |
| 174 | +Maximum milliseconds between client reconnection attempts. |
| 175 | + |
| 176 | +This allows setting an upper bound on how high `#!python REACTPY_RECONNECT_BACKOFF_MULTIPLIER` can increase the time between reconnection attempts. |
| 177 | + |
| 178 | +--- |
| 179 | + |
| 180 | +### `#!python REACTPY_RECONNECT_MAX_RETRIES` |
| 181 | + |
| 182 | +**Default:** `#!python 150` |
| 183 | + |
| 184 | +**Example Value(s):** `#!python 0`, `#!python 5`, `#!python 300` |
| 185 | + |
| 186 | +Maximum number of reconnection attempts before the client gives up. |
| 187 | + |
| 188 | +--- |
| 189 | + |
| 190 | +### `#!python REACTPY_SESSION_MAX_AGE` |
| 191 | + |
| 192 | +**Default:** `#!python 259200` |
| 193 | + |
| 194 | +**Example Value(s):** `#!python 0`, `#!python 60`, `#!python 96000` |
| 195 | + |
| 196 | +Maximum seconds to store ReactPy component sessions. |
| 197 | + |
| 198 | +ReactPy sessions include data such as `#!python *args` and `#!python **kwargs` passed into your `#!jinja {% component %}` template tag. |
50 | 199 |
|
51 |
| -<!--config-table-end--> |
| 200 | +Use `#!python 0` to not store any session data. |
0 commit comments