0

I would like to display the number of online users who are currently on a particular page. How do I go about implementing it?

TIA

H H H
  • 489
  • 1
  • 7
  • 20

1 Answers1

3

Django is purely a server side technology, it responds to http connections usually with html or json. There is no inherent method of discerning a user's current page on the server, merely the last page that may have been requested - the user may be looking at a different tab, have left the site, or the page may have been reloaded from browser cache.

It would be possible to create a Javascript / JQuery plugin on each page, to monitor the user's behaviour and use ajax to communicate with django, something like: How can I detect with JavaScript/jQuery if the user is currently active on the page?.

Possibly a 'heart-beat' function with Javascript would work. This would connect with your django web app every 5 seconds or so, the app could keep a count of unique users, and decrement the counter if a heart-beat is not received.

Is that something like what you are looking for? I would be happy to post some example code if required.

This solution would be accurate every 5 seconds. A less accurate answer would be given by something like django-tracker, which keeps track of users last visited page, in addition it records user activity within your site.

Community
  • 1
  • 1
Henry Florence
  • 2,848
  • 19
  • 16