A
A
Andrei1penguin12021-07-20 17:48:18
Django
Andrei1penguin1, 2021-07-20 17:48:18

How to send a Response to a specific user in Django?

Good day, there is a signal to save the message in the database, that is, when one user sends a message to another, the other (if he is online, that is, he has a web socket open) should receive a notification
. As I understand it, this requires on the client side to send a JsonResponse with the necessary data, but the whole problem is that I do not know how to send a response to a specific user.
That is, something like this:

def notification(sender, **kwargs):
    user = kwargs.get("instance").user
    if user.is_online:
        return JsonResponse(to_client=user)
    else:
        pass

But of course this doesn't work.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
S
Sergey Gornostaev, 2021-07-20
@Andrei1penguin1

No way, answers are sent in response to requests. If the user has a websocket open, then send a notification and and send it.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question