Search code examples
djangowebsocketwebserverdjango-channels

How does django work with websocket server and webserver simultaneously?


I think I have some confusion in the understanding of websocket server and webserver.

So I followed the tutorial of django channels, where I created a little app that listens on a channel and returns some response.

At the same time, I can still serve webpages with normal view functions, so how does django do this magic so that it works without me modifying anything in the nginx server config?


Solution

  • The documentation mentions how this works:

    It separates Django into two process types:

    One that handles HTTP and WebSockets

    One that runs views, websocket handlers and background tasks (consumers) They communicate via a protocol called ASGI, which is similar to WSGI but runs over a network and allows for more protocol types. [...] probably Daphne