Listening to events with consumers
We are going to build an example where we can send messages between a backend and frontend in real time. We will need an intermediary to listen to both and make decisions. Channels comes ready with a specially prepared tool called a consumer. It is a series of functions that are invoked when an event is triggered by a WebSocket client.
Here you can see a minimal consumer structure for WebSockets:
from channels.generic.websocket import WebsocketConsumer class NameConsumer(WebsocketConsumer): def connect(self): """Event when client connects""" # Informs client of successful connection self.accept() def disconnect(self, close_code): """Event when...