I'm working on a project using Python(2.7) and Django(1.11) in which I need to display only logged in users for a specific function.
I have achieved to log out the user by the following settings in settings.py
:
SESSION_COOKIE_AGE = 180
SESSION_SAVE_EVERY_REQUEST = True
LOGOUT_REDIRECT_URL = 'login'
and I need to get active users of type driver
which is I'm getting as:
def get_all_logged_in_users():
# Query all non-expired sessions
# use timezone.now() instead of datetime.now() in latest versions of Django
sessions = Session.objects.filter(expire_date__gte=timezone.now())
uid_list = []
# Build a list of user ids from that query
for session in sessions:
data = session.get_decoded()
print(data)
uid_list.append(data.get('user_id', None))
# Query all logged in users based on id list
return user_table.objects.filter(id__in=uid_list, user_type='driver')
It was working till a few days ago but suddenly stopped working anymore. When I refresh the page after the time SESSION_COOKIE_AGE
passed it redirected to the login page which is perfect but in the database, the is_active
for that user is still True
and it's still displaying in the get_all_logged_in_users
.
How can I solve this issue?