tags:

views:

236

answers:

2

In Django, how can I see the number of current visitors? Or how do I determine the number of active sessions?

Is this a good method?

use django.contrib.sessions.models.Session, set the expiry time short. Every time when somebody does something on the site, update expiry time. Then count the number of sessions that are not expired.

+6  A: 

You might want to look into something like django-tracking for this.

django-tracking is a simple attempt at keeping track of visitors to Django-powered Web sites. It also offers basic blacklisting capabilities.

Edit: As for your updated question... [Answer redacted after being corrected by muhuk]

Alternatively, I liked the response to this question: How do I find out total number of sessions created i.e. number of logged in users?

You might want to try that instead.

bchang
No, Django doesn't store session as cookies, it stores session id's in cookies. And session expiration is stored in session storage. Therefore you can count.
muhuk
Thanks. django-tracking seems to work! (except the part with the fancy map) It looks like an interesting package
Jack Ha
A: 

Edit: Added some more information about why I present this answer here. I found chartbeat when I tried to answer this same question for my django based site. I don't work for them.

Not specifically Django, but chartbeat.com is very interesting to add to a website as well.

django-tracking is great, +1 for that answer, etc.

Couple of things I could not do with django-tracking, that chartbeat helped with; tracked interactions with completely cached pages which never hit the django tracking code and pages not delivered through django (e.g. wordpress, etc.)

dar