Django socket 100

I am trying to chat with django-socketio in my django application.

First, I need to learn about django-socketio, so I read the README https://github.com/stephenmcd/django-socketio

I really want to get the foundation for this. Therefore, I am trying to create a simple thing where the message will be transmitted through socketio.

My .py events:

@events.on_connect def first_connect(request, socket, context): socket.broadcast_channel("my message") 

My opinion:

  def chat(request): return render_to_response('chat.html', {} ,context_instance=RequestContext(request)) 

My URL:

  url(r'^chat/$', 'projet.views.chat'), 

My html:

  <head> {% load socketio_tags %} {% socketio %} <script> var socket = new.io.Socket(); socket.connect(); socket.on('connect', function(){ socket.subscribe('my_channel'); }); </script> </head> 

When I switch to localhost: 8000 / chat, nothing is displayed.

So this is probably very simple, but how can I just send a message through my socket and display it in my html when I connect to it?

I really want to know about this, so if anyone has a tutorial about django-sockieto, I would really appreciate it.

+4
source share
1 answer

You can see the Cody Soyland blog entries here and here . It may be outdated, but I think you can feel what is going on there. Also, this is not about the django socket.

0
source

Source: https://habr.com/ru/post/1446774/


All Articles