Chat server based on Django (ASGI) using WebSocket and Channels.
Based on the tutorial https://channels.readthedocs.io/en/stable/tutorial/part_1.html.
Make sure you have Python3 installed and Docker.
Clone the repo and change to the root of the project:
git clone [email protected]:eclectic-boy/cheeky-chat.git
cd cheeky-chat
Create a Python 3 virtual environment and activate it:
python -m virtualenv .venv -p python3.11
source .venv/bin/activate
Install the requirements:
pip install -r requirements.txt
Start your Redis Docker container:
docker run -p 6379:6379 -d redis:5
Start your Django server
python manage.py runserver
Visit http://127.0.0.1:8000/ to access the chat, there you can decide the name of the room and your username. If you open multiple tabs pointing to the same URL and you use the same room name, then you'll be able to communicate with all those tabs where the messages will be shared.
Django Async capabilities:
How to deploy with ASGI | Django documentation
Asynchronous support | Django documentation
Class-based views | Django documentation
Apparently Django Rest Framework does not support Async views yet, here is the PR: Async implementation by em1208 · Pull Request #8617 · encode/django-rest-framework · GitHub
Apparently this package Channels is the one to be used in Django when dealing with websockets hence Async web features: Django Channels
And there is exactly a tutorial for implementing a chat: Tutorial Part 1: Basic Setup — Channels 4.0.0 documentation