NOTE: This is a work-in-progress/pre-alpha package, and is mostly intended as a proof of concept.
Library to use django-channels within the context of Wagtail, with the first use-case being content-locking.
- Wagtail
- Redis
- In your Wagtail project, run:
pip install git+https://github.com/nypublicradio/wagtail-websockets.git
- Add
channels
andcontent_locking
to yourINSTALLED_APPS
above all the Wagtail imports:
INSTALLED_APPS = [
...
'channels',
'content_locking', # Put this before wagtail apps
...
'wagtail.contrib.forms',
'wagtail.contrib.redirects',
...
]
- In your
settings.py
, add the following block:
# The line below references a file we will create in step 4:
ASGI_APPLICATION = '<YOURPROJECTNAME>.routing.application'
# This references a Redis server that you will need to run - the IP address and
# port should match your own server:
CHANNEL_LAYERS = {
'default': {
'BACKEND': 'channels_redis.core.RedisChannelLayer',
'CONFIG': {
"hosts": [('127.0.0.1', 6379)],
},
},
}
- Create a file called
routing.py
in your main project folder (e.g. the same folder with urls.py):
from channels.auth import AuthMiddlewareStack
from channels.routing import ProtocolTypeRouter, URLRouter
from django.urls import path
from content_locking import routing
application = ProtocolTypeRouter(
{
"websocket": AuthMiddlewareStack(
URLRouter(routing.websocket_urlpatterns)
)
}
)