django channels

so, you mean to say i will have to install daphne for this right?

Well, yea, that too. You need to follow all of the instruction in the docs.

okay, tysm but they have wrote without daphne it is possible so dint installed, ok btw tysm sir, for help let me install daphne and try it

That is correct. You can use a different asgi server such as uvicorn.

But you need an asgi server - it doesn’t matter much which one. That’s why Daphne is marked as optional. You don’t need to use that specific package.

(And you also need a redis server.)

1 Like

pip install channels==3.0.4

use this version it will work, channels 4.0 is not compatible with django 4.0

also change asgi.py
*

import os
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "project.settings")

from channels.auth import AuthMiddlewareStack
from channels.routing import ProtocolTypeRouter, URLRouter
from channels.security.websocket import AllowedHostsOriginValidator
from django.core.asgi import get_asgi_application
from django.urls import path

import django
django.setup()

django_asgi_app = get_asgi_application()

import project.routing

application = ProtocolTypeRouter({
    "http": django_asgi_app,
    "websocket": AllowedHostsOriginValidator(
        AuthMiddlewareStack(
            URLRouter(project.routing.websocket_urlpatterns)
        )
    ),
})

Do not forget to install channels_redis, if youre using redis

pip install channels-redis==4.2.0

I do not believe this is an accurate statement.

Where are you getting this information from?

I see nothing in the docs or the project files that would indicate this.

See channels · PyPI

Brings async, event-driven capabilities to Django 3.2 and up.

These changes may or may not be needed, depending upon how the project is being deployed. The asgi.py as described in the tutorial is adequate when using the Daphne runserver command in development - which is the case here.

But this will work smooth

What will work smooth?

Regardless, neither suggestion addresses the issue that the original author was asking about, and so both really are off-topic for this thread.