Search code examples
djangodjango-channelsdaphneuvicorn

Django Channels Daphne uvicorn


I wrote Django Channels for practice.

Use Daphne

daphne project.asgi:application

Everything works well.

Use uvicorn

uvicorn project.asgi:application

Error on the page

(index):16 WebSocket connection to'ws://127.0.0.1:8000/ws/chat/123/' failed: Error during WebSocket handshake: Unexpected response code: 400

I don't know where I went wrong.

I follow the official use

python -m pip install uvicorn gunicorn

gunicorn project.asgi:application -k uvicorn.workers.UvicornWorker

Error on the page

(index):16 WebSocket connection to'ws://127.0.0.1:8000/ws/chat/123/' failed: Error during WebSocket handshake: Unexpected response code: 400

Please help me where I need to improve, thank you.


Solution

  • If you want to use websockets, you need to install uvicorn[standard]:

    pip install uvicorn[standard]
    

    See also https://www.uvicorn.org/#quickstart