0

I want a function be executed every time a session has expired. Like, recording people viewing specific web page, when user session timeout, decrease the count.

Sudipta
  • 4,773
  • 2
  • 27
  • 42
dspjm
  • 5,473
  • 6
  • 41
  • 62

1 Answers1

0

Instead of trying to execute a function when session expires, you should just query Django session tables from the database to count active sessions.
I don't remember the exact database schema but the query will look similar to:

SELECT COUNT(*) FROM django_session_table WHERE expires > NOW();

As I said, you have to alter the DB table and column names and also the function retrieving the current time is DBMS dependent - NOW() works in PostgreSQL. Please consider this query as a pseudocode then. At the moment I have no possibility to examine Django DB schema but since you use database-backed sessions you already have these in your database, so it should not be a problem to check DB table and column name.

ElmoVanKielmo
  • 10,907
  • 2
  • 32
  • 46