55 <img alt="Tests" src="https://github.com/idom-team/django-idom/workflows/Test/badge.svg?event=push" />
66 </a >
77 <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"/>
99 </a >
1010 <a href =" https://github.com/idom-team/django-idom/blob/main/LICENSE " >
1111 <img alt="License: MIT" src="https://img.shields.io/badge/License-MIT-purple.svg">
@@ -20,14 +20,13 @@ interfaces in pure Python.
2020<a
2121 target="_ blank"
2222 href="https://mybinder.org/v2/gh/idom-team/idom-jupyter/main?filepath=notebooks%2Fintroduction.ipynb">
23- <img
23+ <img
2424 alt="Binder"
2525 valign="bottom"
2626 height="21px"
2727 src="https://mybinder.org/badge_logo.svg"/>
2828</a >
2929
30-
3130# Install Django IDOM
3231
3332``` bash
@@ -46,7 +45,7 @@ your_project/
4645├── urls.py
4746└── example_app/
4847 ├── __init__.py
49- ├── idom .py
48+ ├── components .py
5049 ├── templates/
5150 │ └── your-template.html
5251 └── urls.py
@@ -60,7 +59,7 @@ order to create ASGI websockets within Django. Then, we will add a path for IDOM
6059websocket consumer using ` IDOM_WEBSOCKET_PATH ` .
6160
6261_ 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 ) ._
6463
6564``` python
6665
@@ -75,14 +74,14 @@ os.environ.setdefault("DJANGO_SETTINGS_MODULE", "test_app.settings")
7574# Fetch ASGI application before importing dependencies that require ORM models.
7675http_asgi_app = get_asgi_application()
7776
77+ from channels.auth import AuthMiddlewareStack
7878from channels.routing import ProtocolTypeRouter, URLRouter
7979
8080application = ProtocolTypeRouter(
8181 {
8282 " 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 ]))
8685 ),
8786 }
8887)
@@ -111,6 +110,10 @@ IDOM_BASE_URL: str = "_idom/"
111110# Only applies when not using Django's caching framework (see below).
112111IDOM_WEB_MODULE_LRU_CACHE_SIZE : int | None = None
113112
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+
114117# Configure a cache for loading JS files
115118CACHES = {
116119 # 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`.
147150import idom
148151
149152@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} ! " )
152155```
153156
154157## ` example_app/templates/your-template.html `
@@ -165,8 +168,6 @@ idom_component module_name.ComponentName param_1="something" param_2="something-
165168In context this will look a bit like the following...
166169
167170``` jinja
168- <!-- don't forget your load statements -->
169- {% load static %}
170171{% load idom %}
171172
172173<!DOCTYPE html>
@@ -184,15 +185,11 @@ You can then serve `your-template.html` from a view just
184185[ like any other] ( https://docs.djangoproject.com/en/3.2/intro/tutorial03/#write-views-that-actually-do-something ) .
185186
186187``` python
187- from django.http import HttpResponse
188- from django.template import loader
189-
188+ from django.shortcuts import render
190189
191190def your_view (request ):
192191 context = {}
193- return HttpResponse(
194- loader.get_template(" your-template.html" ).render(context, request)
195- )
192+ return render(request, " your-template.html" , context)
196193```
197194
198195## ` example_app/urls.py `
0 commit comments