django-channels

How to authenticate a user in websocket connection in django channels when using token authentication [duplicate]

只愿长相守 提交于 2019-12-03 09:04:08
This question already has answers here : How do you authenticate a websocket with token authentication on django channels? (5 answers) I am using a frontend framework ( Vuejs ) and django-rest-framework for the REST API in my project. Also, for JSON web token authentication I am using django-rest-framework-jwt . After a successful login, the user is provided with a token. This token is passed into every request to fetch any API related stuff. Now I would like to integrate django channels into my project. So, after successful login, when the token is received in the client side, I would like to

Session authentication with Django channels

╄→尐↘猪︶ㄣ 提交于 2019-12-03 07:08:35
问题 Trying to get authentication working with Django channels with a very simple websockets app that echoes back whatever the user sends over with a prefix "You said: " . My processes: web: gunicorn myproject.wsgi --log-file=- --pythonpath ./myproject realtime: daphne myproject.asgi:channel_layer --port 9090 --bind 0.0.0.0 -v 2 reatime_worker: python manage.py runworker -v 2 I run all processes when testing locally with heroku local -e .env -p 8080 , but you could also run them all separately.

Django channels - Echo example not working

好久不见. 提交于 2019-12-03 02:47:42
I'm following the instructions in the documentation site , but I got stuck in the echo example, the websocket is created correctly and it's connected to the server but when I send anything to the server I'm not getting any response (In the example says I should see an alert window with the same message that I send into the socket but I don't, although I've changed the alert for a console.log but still), what I'm doing wrong? In settings.py : INSTALLED_APPS = { ... 'channels', 'myapp', ... } ... # Channels settings CHANNEL_LAYERS = { "default": { "BACKEND": "asgiref.inmemory.ChannelLayer",

Sending messages to groups in Django Channels 2

ぐ巨炮叔叔 提交于 2019-12-02 23:41:58
I am completely stuck in that I cannot get group messaging to work with Channels 2! I have followed all tutorials and docs that I could find, but alas I haven't found what the issue seems to be yet. What I am trying to do right now is to have one specific URL that when visited should broadcast a simple message to a group named "events". First things first, here are the relevant and current settings that I employ in Django: CHANNEL_LAYERS = { 'default': { 'BACKEND': 'channels_redis.core.RedisChannelLayer', 'CONFIG': { 'hosts': [('localhost', 6379)], }, } } ASGI_APPLICATION = 'backend.routing

Django channels 'No application configured for scope type 'websocket''

我的未来我决定 提交于 2019-12-02 03:34:17
I am trying to implement a chat with Django and channels according to this tutorial ( http://channels.readthedocs.io/en/latest/tutorial/part_2.html ). I add channels and a chat app to installed apps. I make the following routings for a project: # mysite/routing.py from channels.routing import ProtocolTypeRouter application = ProtocolTypeRouter({ # (http->django views is added by default) }) Basically, I did exactly the steps from the tutorial. But after runserver I am still getting ValueError: No application configured for scope type 'websocket' , after going to a specific chat room. Can

Django Channels Error - Cannot import BACKEND 'asgi_redis.RedisChannelLayer'

牧云@^-^@ 提交于 2019-12-01 00:06:20
问题 I have installed Django-Channels but while running the daphne-server I am getting this error given below: File "/usr/local/lib/python2.7/dist-packages/channels/asgi.py", line 36, in make_backend "Cannot import BACKEND %r specified for %s" % (self.configs[name]['BACKEND'], name) channels.asgi.InvalidChannelLayerError: Cannot import BACKEND 'asgi_redis.RedisChannelLayer' specified for default My settings.py is: CHANNEL_LAYERS = { "default": { "BACKEND": "asgi_redis.RedisChannelLayer", "CONFIG":

Running django channels with daphne on systemd

拜拜、爱过 提交于 2019-11-30 16:20:50
First of all, sorry for the long question, I hope a few of you have patience for this. TL; DR: How do I load django settings correctly in systemd? I am following this guide, Deploying Django Channels Using Daphne , so I can run some real-time apps (using WebSockets). Without nginx, and running from the command line the worker (python manage.py runworker) and interface (daphne), I can access the correct channels consumer class, as can be seen in the log below (these were triggered from a javascript client): 2017-10-09 21:10:35,210 - DEBUG - worker - Got message on websocket.connect (reply

Django Channels - constantly send data to client from server

房东的猫 提交于 2019-11-30 12:19:49
问题 Please take a look at this example. As you can see, some sort of event is constantly being sent to the client. I want to imitate this using Django-Channels , inside consumers.py . Here's a simplified version of what I have: class ChatConsumer(AsyncConsumer): async def ws_connect(self, event): self.send = get_db_object() .... await self.send({ "type": "websocket.accept" }) # I need to CONSTANTLY receive & send data async def ws_receive(self, event): obj = ...# query DB and get the newest

Django Channels - constantly send data to client from server

早过忘川 提交于 2019-11-30 02:29:20
Please take a look at this example . As you can see, some sort of event is constantly being sent to the client. I want to imitate this using Django-Channels , inside consumers.py . Here's a simplified version of what I have: class ChatConsumer(AsyncConsumer): async def ws_connect(self, event): self.send = get_db_object() .... await self.send({ "type": "websocket.accept" }) # I need to CONSTANTLY receive & send data async def ws_receive(self, event): obj = ...# query DB and get the newest object json_obj = { 'field_1': obj.field_1, 'field_2': obj.field_2, } await self.send({ "type": "websocket

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

馋奶兔 提交于 2019-11-28 19:40:46
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 consumer that on connect will set the user status to 'online' , while when the socket get disconnected