django channels help please

31 views
Skip to first unread message

정정수

unread,
Feb 26, 2019, 5:02:42 AM2/26/19
to Django users
Hi Dear
( I use Google Translator ) 
I'm Korea devoleper,
please help,

I am developing two projects.
I saw the tutorial and created chat features for both projects.
The code for both projects is the same.  
But one of them is a problem.


[A user] creates a chat room and enters [B user].
Chatting is good so far.
However, if [B user] creates a room for another room_name
You can not chat in both rooms.

It does not pass from receive in consumers.py to chat_message.
( Chatting alone will be done immediately after [B user] creates a room. 
  The chat_room of [A user], [B user] Only two or three chats are available.)


Emphasize again, one of the projects works normally. 

 
I have not been able to fix it for a few days.......
Please help me.....ㅜ_ㅜ

Thank you.
Good day.

Ahmed Ishtiaque

unread,
Feb 26, 2019, 5:59:13 AM2/26/19
to django...@googlegroups.com
Could you share your repository? We need more details to determine what’s wrong. 

On a side note, I made a functional chat app with Django channels here: https://www.github.com/dibs-devs/chatter

Good luck!
--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users...@googlegroups.com.
To post to this group, send email to django...@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/8f1694cf-59f3-47b7-b55b-3c777a6d4e01%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

egbosi Kelechi

unread,
Feb 26, 2019, 7:20:57 AM2/26/19
to django...@googlegroups.com
What version of channels are you using?
How do you determine the channel _name for each chat rooms?

Could you share some code? 

--

정정수

unread,
Feb 26, 2019, 8:43:24 PM2/26/19
to Django users
https://channels.readthedocs.io/en/latest/index.html

Viewed and produced basic tutorials

I'd like to show you if there's anything special about the code
It is 100% identical to the tutorial code



<!-- chat/templates/chat/index.html -->
<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8"/>
    <title>Chat Rooms</title>
</head>
<body>
    What chat room would you like to enter?<br/>
    <input id="room-name-input" type="text" size="100"/><br/>
    <input id="room-name-submit" type="button" value="Enter"/>

    <script>
        document.querySelector('#room-name-input').focus();
        document.querySelector('#room-name-input').onkeyup = function(e) {
            if (e.keyCode === 13) {  // enter, return
                document.querySelector('#room-name-submit').click();
            }
        };

        document.querySelector('#room-name-submit').onclick = function(e) {
            var roomName = document.querySelector('#room-name-input').value;
            window.location.pathname = '/chat/' + roomName + '/';
        };
    </script>
</body>
</html>



html that specifies room_name.
The same thing happens to any room_name



2019년 2월 26일 화요일 오후 7시 2분 42초 UTC+9, 정정수 님의 말:

Ahmed Ishtiaque

unread,
Feb 26, 2019, 8:59:06 PM2/26/19
to django...@googlegroups.com
Is any error produced on your development server? Please post the code in your consumers.py file.

--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users...@googlegroups.com.
To post to this group, send email to django...@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.

정정수

unread,
Feb 26, 2019, 9:04:28 PM2/26/19
to Django users
The development server does not display an error.
This is the same as normal operation.
However, the information is not sent to chat_message.


# chat/consumers.py
from channels.generic.websocket import AsyncWebsocketConsumer
import json

class ChatConsumer(AsyncWebsocketConsumer):
    async def connect(self):
        self.room_name = self.scope['url_route']['kwargs']['room_name']
        self.room_group_name = 'chat_%s' % self.room_name

        # Join room group
        await self.channel_layer.group_add(
            self.room_group_name,
            self.channel_name
        )

        await self.accept()

    async def disconnect(self, close_code):
        # Leave room group
        await self.channel_layer.group_discard(
            self.room_group_name,
            self.channel_name
        )

    # Receive message from WebSocket
    async def receive(self, text_data):
        text_data_json = json.loads(text_data)
        message = text_data_json['message']

        # Send message to room group
        await self.channel_layer.group_send(
            self.room_group_name,
            {
                'type': 'chat_message',
                'message': message
            }
        )

    # Receive message from room group
    async def chat_message(self, event):
        message = event['message']

        # Send message to WebSocket
        await self.send(text_data=json.dumps({
            'message': message
        }))



Thank you for your help.


2019년 2월 26일 화요일 오후 7시 2분 42초 UTC+9, 정정수 님의 말:
Hi Dear
Reply all
Reply to author
Forward
0 new messages