5
5
<img alt="Tests" src="https://github.com/idom-team/django-idom/workflows/Test/badge.svg?event=push" />
6
6
</a >
7
7
<a href =" https://pypi.python.org/pypi/django-idom " >
8
- <img alt="Version Info" src="https://img.shields.io/pypi/v/idom.svg"/>
8
+ <img alt="Version Info" src="https://img.shields.io/pypi/v/django- idom.svg"/>
9
9
</a >
10
10
<a href =" https://github.com/idom-team/django-idom/blob/main/LICENSE " >
11
11
<img alt="License: MIT" src="https://img.shields.io/badge/License-MIT-purple.svg">
@@ -20,14 +20,13 @@ interfaces in pure Python.
20
20
<a
21
21
target="_ blank"
22
22
href="https://mybinder.org/v2/gh/idom-team/idom-jupyter/main?filepath=notebooks%2Fintroduction.ipynb">
23
- <img
23
+ <img
24
24
alt="Binder"
25
25
valign="bottom"
26
26
height="21px"
27
27
src="https://mybinder.org/badge_logo.svg"/>
28
28
</a >
29
29
30
-
31
30
# Install Django IDOM
32
31
33
32
``` bash
@@ -46,7 +45,7 @@ your_project/
46
45
├── urls.py
47
46
└── example_app/
48
47
├── __init__.py
49
- ├── idom .py
48
+ ├── components .py
50
49
├── templates/
51
50
│ └── your-template.html
52
51
└── urls.py
@@ -60,7 +59,7 @@ order to create ASGI websockets within Django. Then, we will add a path for IDOM
60
59
websocket consumer using ` IDOM_WEBSOCKET_PATH ` .
61
60
62
61
_ Note: If you wish to change the route where this websocket is served from, see the
63
- available [ settings] ( #settings.py ) ._
62
+ available [ settings] ( #settingspy ) ._
64
63
65
64
``` python
66
65
@@ -75,14 +74,14 @@ os.environ.setdefault("DJANGO_SETTINGS_MODULE", "test_app.settings")
75
74
# Fetch ASGI application before importing dependencies that require ORM models.
76
75
http_asgi_app = get_asgi_application()
77
76
77
+ from channels.auth import AuthMiddlewareStack
78
78
from channels.routing import ProtocolTypeRouter, URLRouter
79
79
80
80
application = ProtocolTypeRouter(
81
81
{
82
82
" http" : http_asgi_app,
83
- " websocket" : URLRouter(
84
- # add a path for IDOM's websocket
85
- [IDOM_WEBSOCKET_PATH ]
83
+ " websocket" : SessionMiddlewareStack(
84
+ AuthMiddlewareStack(URLRouter([IDOM_WEBSOCKET_PATH ]))
86
85
),
87
86
}
88
87
)
@@ -111,6 +110,10 @@ IDOM_BASE_URL: str = "_idom/"
111
110
# Only applies when not using Django's caching framework (see below).
112
111
IDOM_WEB_MODULE_LRU_CACHE_SIZE : int | None = None
113
112
113
+ # Maximum seconds between two reconnection attempts that would cause the client give up.
114
+ # 0 will disable reconnection.
115
+ IDOM_WS_MAX_RECONNECT_DELAY : int = 604800
116
+
114
117
# Configure a cache for loading JS files
115
118
CACHES = {
116
119
# Configure a cache for loading JS files for IDOM
@@ -147,8 +150,8 @@ ultimately be referenced by name in `your-template.html`. `your-template.html`.
147
150
import idom
148
151
149
152
@idom.component
150
- def Hello (greeting_recipient ): # component names are camelcase by convention
151
- return Header (f " Hello { greeting_recipient} ! " )
153
+ def Hello (websocket , greeting_recipient ): # component names are camelcase by convention
154
+ return idom.html.header (f " Hello { greeting_recipient} ! " )
152
155
```
153
156
154
157
## ` example_app/templates/your-template.html `
@@ -165,8 +168,6 @@ idom_component module_name.ComponentName param_1="something" param_2="something-
165
168
In context this will look a bit like the following...
166
169
167
170
``` jinja
168
- <!-- don't forget your load statements -->
169
- {% load static %}
170
171
{% load idom %}
171
172
172
173
<!DOCTYPE html>
@@ -184,15 +185,11 @@ You can then serve `your-template.html` from a view just
184
185
[ like any other] ( https://docs.djangoproject.com/en/3.2/intro/tutorial03/#write-views-that-actually-do-something ) .
185
186
186
187
``` python
187
- from django.http import HttpResponse
188
- from django.template import loader
189
-
188
+ from django.shortcuts import render
190
189
191
190
def your_view (request ):
192
191
context = {}
193
- return HttpResponse(
194
- loader.get_template(" your-template.html" ).render(context, request)
195
- )
192
+ return render(request, " your-template.html" , context)
196
193
```
197
194
198
195
## ` example_app/urls.py `
0 commit comments