I am facing an error in django-channels, where it says:
Not Found: /ws/jokes/
here is my
consumers.py:
from channels.generic.websocket import AsyncWebsocketConsumer
class JokesConsumer(AsyncWebsocketConsumer):
async def connect(self):
await self.channel_layer.group_add('jokes', self.channel_name)
await self.accept()
async def disconnect(self):
await self.channel_layer.group_discard('jokes', self.channel_name)
async def send_jokes(self, event):
text_message = event['text']
await self.send(text_message)
here is the:
routing.py:
from django.urls import path
from .consumers import JokesConsumer
ws_urlpatterns = [
path('ws/jokes/', JokesConsumer.as_asgi())
]
and here is the
asgi.py:
import os
from django.core.asgi import get_asgi_application
from channels.auth import AuthMiddlewareStack
from channels.routing import ProtocolTypeRouter, URLRouter
from jokes.routing import ws_urlpatterns
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'jokes_project.settings')
application = ProtocolTypeRouter({
'http': get_asgi_application(),
'websocket': AuthMiddlewareStack(URLRouter(ws_urlpatterns)),
})
I have added the CHANNEL_LAYERS in the settings.py, also I have set ASGI_APPLICATION, and celery_broker_url.