File tree Expand file tree Collapse file tree 2 files changed +3
-3
lines changed Expand file tree Collapse file tree 2 files changed +3
-3
lines changed Original file line number Diff line number Diff line change @@ -433,7 +433,7 @@ following code in ``chat/consumers.py``, replacing the old code:
433
433
class ChatConsumer (WebsocketConsumer ):
434
434
def connect (self ):
435
435
self .room_name = self .scope[" url_route" ][" kwargs" ][" room_name" ]
436
- self .room_group_name = " chat_%s " % self .room_name
436
+ self .room_group_name = f " chat_ { self .room_name} "
437
437
438
438
# Join room group
439
439
async_to_sync(self .channel_layer.group_add)(
@@ -481,7 +481,7 @@ Several parts of the new ``ChatConsumer`` code deserve further explanation:
481
481
including in particular any positional or keyword arguments from the URL
482
482
route and the currently authenticated user if any.
483
483
484
- * ``self.room_group_name = "chat_%s" % self.room_name ``
484
+ * ``self.room_group_name = f "chat_{ self.room_name}" ``
485
485
* Constructs a Channels group name directly from the user-specified room
486
486
name, without any quoting or escaping.
487
487
* Group names may only contain alphanumerics, hyphens, underscores, or
Original file line number Diff line number Diff line change @@ -40,7 +40,7 @@ Put the following code in ``chat/consumers.py``:
40
40
class ChatConsumer (AsyncWebsocketConsumer ):
41
41
async def connect (self ):
42
42
self .room_name = self .scope[" url_route" ][" kwargs" ][" room_name" ]
43
- self .room_group_name = " chat_%s " % self .room_name
43
+ self .room_group_name = f " chat_ { self .room_name} "
44
44
45
45
# Join room group
46
46
await self .channel_layer.group_add(self .room_group_name, self .channel_name)
You can’t perform that action at this time.
0 commit comments