django-channels

Django - How to track if a user is online/offline in realtime?

给你一囗甜甜゛ 提交于 2019-11-27 12:27:36
问题 I'm considering to use django-notifications and Web Sockets to send real-time notifications to iOS/Android and Web apps. So I'll probably use Django Channels . Can I use Django Channels to track online status of an user real-time? If yes then how I can achieve this without polling constantly the server? I'm looking for a best practice since I wasn't able to find any proper solution. UPDATE : What I have tried so far is the following approach: Using Django Channels, I implemented a WebSocket

How do you authenticate a websocket with token authentication on django channels?

为君一笑 提交于 2019-11-27 12:05:27
问题 We want to use django-channels for our websockets but we need to authenticate as well. We have a rest api running with django-rest-framework and there we use tokens to authenticate a user, but the same functionality does not seem to be built into django-channels. 回答1: For Django-Channels 2 you can write custom authentication middleware https://gist.github.com/rluts/22e05ed8f53f97bdd02eafdf38f3d60a token_auth.py: from channels.auth import AuthMiddlewareStack from rest_framework.authtoken