I have this javascript code that send data to channels
// Note that the path doesn't matter for routing; any WebSocket
// connection gets bumped over to WebSocket consumers
socket = new WebSocket("ws://" + window.location.host + "/chat/");
socket.onmessage = function(e) {
alert(e.data);
}
socket.onopen = function() {
socket.send({"test":"data"});
}
// Call onopen directly if socket is already open
if (socket.readyState == WebSocket.OPEN) socket.onopen();
I'm curios how from message I can get the json {"test":"data"}
here's the view
# Connected to websocket.connect
@channel_session
def ws_connect(message, key):
# Accept connection
message.reply_channel.send({"accept": True})
if i try message.content['test'] I get a key error
key = message['test']
File "/usr/local/lib/python2.7/dist-packages/channels/message.py", line
36, in __getitem__
return self.content[key]
KeyError: 'test'
--
Best Regards,
Samuel Muiruri.
Web Designer | +254 738 940064
--
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 [email protected].
To post to this group, send email to [email protected].
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/CAJZFZXpbC%2BZ9xSWumRVALKMnt29DkTLchUtKBvkBJyXBh43nQw%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.