Home>

Please tell me why I can't connect to a web socket following this tutorial https://channels.readthedocs.io/en/stable/tutorial/

I configured everything as in the example, only I have everything deployed in docker. The site starts up, everything works, but there is no connection to the socket.

I have an app

settings.py:

INSTALLED_APPS= [
    'jazzmin',
    ...
    'debug_toolbar',
    'django_extensions',
    'rest_framework',
    'drf_yasg',
    'channels',
    'chat',
]
ASGI_APPLICATION= "app.asgi.application"
CHANNEL_LAYERS= {
"default": {
    "BACKEND": "channels.layers.InMemoryChannelLayer"
}

}

app /routing.py

from channels.routing import ProtocolTypeRouter, URLRouter
import chat.routing
application= ProtocolTypeRouter (
    {"websocket": URLRouter (chat.routing.websocket_urlpatterns)}
)

chat /routing.py

from django.urls import re_path
from. import consumers
websocket_urlpatterns= [
    re_path (r'ws /chat /(? P <
room_name >
\ w +) /$ ', consumers.ChatConsumer.as_asgi ()),
]

what is routing.py?

finally2021-12-31 10:45:09

what's in the logs? (you may have to remove the django debug toolbar from the project as it eats up the djanog channels logs)

Антон2021-12-31 10:45:09

@Anton there are no errors in the logs, there is simply no connection to the socket

Oleksandr2021-12-31 10:45:09

@finally this is the routing for web sockets

Oleksandr2021-12-31 10:45:09