Tutorial Part 1: Basic Setup
Add Channels and Daphne to locallibrary and create the chat app’s index page.
2 minute read
Channels allows you to use WebSockets and other non-HTTP protocols in your Django site. For example you might want to use WebSockets to allow a page on your site to immediately receive updates from your Django server without using HTTP long-polling or other expensive techniques.
In this tutorial we will build a simple chat server, where you can join an online room, post messages to the room, and have others in the same room see those messages immediately.
This is a copy of the official Channels tutorial, changed to match the way we have worked in our fork of the MDN Django Tutorial:
chat app goes into your existing locallibrary repository, next to catalog. Everywhere the original says mysite, this copy says locallibrary_config.pip install becomes uv add, and every command is run with uv run python ….settings.py and urls.py contents because it assumes a new, empty project. Here you only add lines, so you keep what you built for catalog.This copy was checked on 2026-09-29 with Channels 4.3.2, Daphne 4.2.3, channels-redis 4.3.0, Selenium 4.49, Django 6.1.1, and Python 3.14.
The original tutorial is Copyright (c) Django Software Foundation and individual contributors, and is used under its BSD 3-Clause license.
Add Channels and Daphne to locallibrary and create the chat app’s index page.
Add the room view, a WebSocket consumer, and a Redis-backed channel layer.
Rewrite ChatConsumer as an asynchronous consumer.
End-to-end tests for the chat server with Selenium and ChannelsLiveServerTestCase.