Skip to content

Commit 31cd427

Browse files
authored
Update tutorial to use period style event types (#2001)
1 parent fb7c67a commit 31cd427

File tree

2 files changed

+5
-3
lines changed

2 files changed

+5
-3
lines changed

docs/tutorial/part_2.rst

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -455,7 +455,7 @@ following code in ``chat/consumers.py``, replacing the old code:
455455
456456
# Send message to room group
457457
async_to_sync(self.channel_layer.group_send)(
458-
self.room_group_name, {"type": "chat_message", "message": message}
458+
self.room_group_name, {"type": "chat.message", "message": message}
459459
)
460460
461461
# Receive message from room group
@@ -514,7 +514,9 @@ Several parts of the new ``ChatConsumer`` code deserve further explanation:
514514
* ``async_to_sync(self.channel_layer.group_send)``
515515
* Sends an event to a group.
516516
* An event has a special ``'type'`` key corresponding to the name of the method
517-
that should be invoked on consumers that receive the event.
517+
that should be invoked on consumers that receive the event. This translation
518+
is done by replacing ``.`` with ``_``, thus in this example, ``chat.message``
519+
calls the ``chat_message`` method.
518520

519521
Let's verify that the new consumer for the ``/ws/chat/ROOM_NAME/`` path works.
520522
To start the Channels development server, run the following command:

docs/tutorial/part_3.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ Put the following code in ``chat/consumers.py``:
5858
5959
# Send message to room group
6060
await self.channel_layer.group_send(
61-
self.room_group_name, {"type": "chat_message", "message": message}
61+
self.room_group_name, {"type": "chat.message", "message": message}
6262
)
6363
6464
# Receive message from room group

0 commit comments

Comments
 (0)