Answer the question
In order to leave comments, you need to log in
How to access the session of a specific user?
Good day, there is a task to determine whether the user is on the site or not.
When the user enters the site, a session is created.
Actually, the task is: to access this session through the user, but I don’t really understand how this can be done
Alternatively, it's probably possible to change the user's is_active value to True or False every time they enter and exit the site, but I suspect that this is not the best idea
Answer the question
In order to leave comments, you need to log in
Django runs over HTTP, which is a stateless protocol. Without WebSockets or front-end polling, there's no way you can reliably tell if a user is on the site.
Andrei1penguin1 you can try to do something like this, in the user model create a field "last visit time", create an online method there to check this field, if it is greater than the current time minus 5 minutes, then the user is online. This field can be updated in such a way that, through middleware, update this field with each request, and also place a script in html that will send a request to the server for some minimal page at intervals of 1 minus, thus updating the field of the last visit to the site
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question