2021-03-01
2526
#django
Gaurav Singhal
35014
Mar 1, 2021 â‹… 9 min read

Django Channels and WebSockets

Gaurav Singhal Gaurav is a data scientist with a strong background in computer science and mathematics. As a developer, he works with Python, Java, Django, HTML, Struts, Hibernate, Vaadin, web scraping, Angular, and React.

Recent posts:

Understanding The Css Revert Layer Keyword, Part Of Css Cascade Layers

Understanding the CSS revert-layer keyword

In this article, we’ll explore CSS cascade layers — and, specifically, the revert-layer keyword — to help you refine your styling strategy.

Chimezie Innocent
Apr 24, 2024 â‹… 6 min read
Exploring Nushell, A Rust Powered, Cross Platform Shell

Exploring Nushell, a Rust-powered, cross-platform shell

Nushell is a modern, performant, extensible shell built with Rust. Explore its pros, cons, and how to install and get started with it.

Oduah Chigozie
Apr 23, 2024 â‹… 6 min read
Exploring Zed, A Newly Open Source Code Editor Written In Rust

Exploring Zed, an open source code editor written in Rust

The Zed code editor sets itself apart with its lightning-fast performance and cutting-edge collaborative features.

Nefe Emadamerho-Atori
Apr 22, 2024 â‹… 7 min read
Implementing Infinite Scroll In Next Js With Server Actions

Implementing infinite scroll in Next.js with Server Actions

Infinite scrolling in Next.js no longer requires external libraries — Server Actions let us fetch initial data directly on the server.

Rahul Chhodde
Apr 19, 2024 â‹… 10 min read
View all posts

6 Replies to "Django Channels and WebSockets"

  1. Great tutorial!

    Everything works right out of the box except for the following minor details

    – move extends directive to top of file in game/templates/main.html
    – remove extraneous backslashes from game/consumers.py
    self.room_name = self.scope\[‘url_route’\][‘kwargs’][‘room_code’]

    1. none of this works for me…
      GEThttp://localhost:8081/favicon.ico
      [HTTP/1.1 404 Not Found 0ms]

      GETws://localhost:8081/ws/play/xxx/
      [HTTP/1.1 404 Not Found 7ms]

      Firefox can’t establish a connection to the server at ws://localhost:8081/ws/play/xxx/. game.js:5:17
      Socket is closed. Reconnect will be attempted in 1 second. game.js:132:17

  2. Great tutorial, in addition to Silkentrance updates, for django 4 I had to make the following changes:

    – game.js – change event.path[0] to event.composedPath()[0]
    – routing.py – change django.conf.urls import url to from django.urls import re_path
    – routing.py – change url to re_path in websocket_urlpatterns

    Thank you for putting this together!

Leave a Reply