Django Channels Tutorial

Our copy of the Django Channels tutorial, adapted for uv and your locallibrary project.

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.

  1. Part 1: Basic Setup
  2. Part 2: Implement a Chat Server
  3. Part 3: Rewrite Chat Server as Asynchronous
  4. Part 4: Automated Testing

How this copy differs from the original

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:

  • You don’t create a new project. The chat app goes into your existing locallibrary repository, next to catalog. Everywhere the original says mysite, this copy says locallibrary_config.
  • Dependencies are managed with uv. pip install becomes uv add, and every command is run with uv run python ….
  • Edits to existing files are additions. The original shows complete 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.
  • Part 4’s tests use a separate database file. The original’s test settings would delete your development database; this copy’s don’t.
  • Part 4 doesn’t need a manual chromedriver install. Selenium downloads the right driver itself.

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.


Tutorial Part 1: Basic Setup

Add Channels and Daphne to locallibrary and create the chat app’s index page.

Tutorial Part 2: Implement a Chat Server

Add the room view, a WebSocket consumer, and a Redis-backed channel layer.

Tutorial Part 3: Rewrite Chat Server as Asynchronous

Rewrite ChatConsumer as an asynchronous consumer.

Tutorial Part 4: Automated Testing

End-to-end tests for the chat server with Selenium and ChannelsLiveServerTestCase.

Last modified September 29, 2026: add diff (6bfd0e7)