FZambia / django-realtime-playground

Django chat application using different realtime technologies. Out of date! See https://github.com/centrifugal/centrifugo and https://github.com/django/channels
76 stars 10 forks source link

Django Realtime Playground

This is a set of experiments with various modern realtime libraries and asynchronous servers/frameworks together with Django. Personally I suggest using Centrifugo to add real-time on your Django site as most of solutions here is just a showcase

Includes:

At this moment there are some possible implementations of chat's realtime part using one of javascript libraries and one of async backend server:

Install and run

1) Clone this repo:

git clone https://github.com/FZambia/django-realtime-playground.git django-realtime-playground/
cd django-realtime-playground

2) I suppose that you are familiar with virtualenv. Let's run our Django application:

pip install -r django/requirements.txt
cd django
# for django < 1.7
python manage.py syncdb
# for django >= 1.7 use migrate command
# python manage.py migrate

Create new superuser and run server:

python manage.py createsuperuser
python manage.py runserver

Go to http://localhost:8000 and make sure that everything works.

3) As you can see after successful login into Django site - you can choose one of options how chat will work. Choose one.

home

But before you click 'READY' button you must run appropriate async server. Look at folders - they named exactly as options. Now I should tell you how to run each of those servers.

4) After running appropriate async server you can click on button 'READY' and proceed to chat. Chat behaviour is the same for any of options selectedв

chat

By default every async server will run on port 8001, but you can easily change it in code. But do not forget to change ASYNC_BACKEND_URL in Django's settings.py

How it works.

We can not allow bidirectional communication between client and async server because of authorization. So every event you create goes to Django. Then Django makes POST request to async server which broadcasts those event to all connected clients.