When i Hit This Url Then This Error Comes
ws://localhost:8000/ws/test/
Error On My Terminal
[31/Oct/2023 10:46:05] "GET /ws/ HTTP/1.1" 404 2090
[31/Oct/2023 10:46:08] "GET / HTTP/1.1" 200 10664
[31/Oct/2023 10:46:08,884] - Broken pipe from ('127.0.0.1', 43236)
Not Found: /ws/test/
[31/Oct/2023 10:46:11] "GET /ws/test/ HTTP/1.1" 404 2105
[31/Oct/2023 10:46:11,513] - Broken pipe from ('127.0.0.1', 43252)
My Consumers.py
from channels.generic.websocket import WebsocketConsumer
from asgiref.sync import async_to_sync
import json
class TestConsumer(WebsocketConsumer):
def connect(self):
self.room_name = "test_consumer"
self.room_group_name = "test_consumer_group"
async_to_sync(self.channel_layer.group_send)(
self.room_name, self.room_group_name
)
self.accept()
self.send(text_data=json.dumps({'status': 'Connected'}))
def receive(self, text_data):
pass
def disconnect(self, close_code):
pass
Asgi.py
import os
from channels.routing import ProtocolTypeRouter, URLRouter
from django.urls import path
from django.core.asgi import get_asgi_application
from myapp.consumers import TestConsumer
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'mychannels.settings')
application = get_asgi_application()
ws_patterns = [
path('ws/test/', TestConsumer)
]
application = ProtocolTypeRouter({
'websocket': URLRouter(ws_patterns)
})
Settings.py
ASGI_APPLICATION = 'mychannels.asgi.application'
channels_layers = {
'default': {
'BACKEND': 'channels_redis.core.RedisChannelLayer',
'CONFIG': {
'hosts': [('localhost', 6379)],
},
},
}