In template, when I use
{% if topic.creator.is_authenticated %}
Online
{% else %}
Offline
{% endif %}
the users turn out to be always onli
The reason a user appears to always be online is described in the Django documentation:
is_authenticated()
- Always returns
True... This is a way to tell if the user has been authenticated. This does not imply any permissions, and doesn’t check if the user is active or has a valid session.
There are a number of ways you could achieve this, but none are "build-in".
This question covers the last activity time of a user, and you could use that to check if a user was active in the past few minutes.
Alternatively, you can query the Session table to check if the user has an active session, but this may be inaccurate if you have long session timeouts.