11👍
Django isn’t good at “pushing” things to the client. If django is your only option, the only way to mimic a push is via long-polling. But this is not efficient. Instead, websockets are hot. Tornado and twisted can help you here. There is also a more complete answer to your question here.
14👍
One option would be to use a WebSocket server running parallel to your Django server which has a REST/Push API, and then do pushes from Django by simply HTTP/POSTing to the WebSocket server, which in turn delivers the messages to all connected WebSocket clients.
That way, you don’t need any structural/technical changes to your existing Django app, nevertheless have a scalable, modern WebSocket based push feature.
For a hosted service providing above, I’d have a look at http://pusher.com.
If you prefer running your own, I’d have a look at http://autobahn.ws, which is deployed as a ready-to-run virtual appliance (VMware, VirtualBox, Amazon EC2). You can find working examples of REST/API here https://github.com/tavendo/AutobahnPushPython
Disclaimer: I am author of Autobahn Open-source, and work for Tavendo, which offers Autobahn.ws (the commercial offering based on Autobahn OSS).
- [Django]-Django: Get model from string?
- [Django]-Django + apache & mod_wsgi: having to restart apache after changes
- [Django]-Multiple django sites with apache & mod_wsgi
9👍
Another implementation of websockets in Django:
https://github.com/jonashagstedt/swampdragon
From docs: SwampDragon makes use of Djangos wonderful ORM, Tornados excellent websocket support (with fallback. Tested in IE7), and Redis blazing speed.
- [Django]-How to convert a Django QuerySet to a list?
- [Django]-Django Migration Error: Column does not exist
- [Django]-In a Django form, how do I make a field readonly (or disabled) so that it cannot be edited?
9👍
As of 2016, there is Django Channels, which brings websockets to Django (1.8 and higher).
It is also part of the official Django project.
- [Django]-How can I login to django using tastypie
- [Django]-Django test to use existing database
- [Django]-Guide in organizing large Django projects
6👍
There is a Django module, which supports websockets out of the box using Redis as message queue.
Have a look here: https://github.com/jrief/django-websocket-redis
Disclaimer: I am the author of that library.
- [Django]-Django accessing ForeignKey model objects
- [Django]–bash: ./manage.py: Permission denied
- [Django]-Can you give a Django app a verbose name for use throughout the admin?
5👍
As @hymloth suggests, a better way is to use tornado or node.js.
But, if you have to use Django, I’ve wrote an article about implementing WebSocket with it that you might find useful.
http://curella.org/blog/2012/jul/17/django-push-using-server-sent-events-and-websocket/
- [Django]-Understanding Django-LDAP authentication
- [Django]-Problems with contenttypes when loading a fixture in Django
- [Django]-Remove leading and trailing slash / in python
- [Django]-How to reset migrations in Django 1.7
- [Django]-How to exempt CSRF Protection on direct_to_template
- [Django]-Django, query filtering from model method