Django Channels understanding

33 views
Skip to first unread message

chinmay...@gmail.com

unread,
Dec 7, 2020, 12:26:23 PM12/7/20
to Django users
I created a Consumer class with AsyncJsonWebsocketConsumer
and initialized a <groups> variable with an array ['test'];
such that "test" becomes one of the groups(or broadcast room)
In the following code  
```
async def connect(self):
        await self.channel_layer.group_add(
            group='test',
            channel=self.channel_name
        )
        print("THE CHANNEL NAME IS ------------> ", self.channel_name)
        await self.accept()
```
My query is what exactly is self.channel_name and is it just a convention and I should be bothered by it.
Because when I declare (following is the code for same) I don't pass any channel_name 
```
settings.CHANNEL_LAYERS = TEST_CHANNEL_LAYERS
        communicator = WebsocketCommunicator(
            application=application,
            path='/sepsisDynamic/'
        )
        connected, _ = await communicator.connect()
        message = {
            'type': 'echo.message',
            'data': 'This is a test message.',
        }
        channel_layer = get_channel_layer()
        await channel_layer.group_send('test', message=message)
```
I believe it's built-in functionality but I am curious what exactly it does.

Reply all
Reply to author
Forward
0 new messages