How do I know if a specific user is registered in Django, and not the current requesting user?

How do I know if a specific user is registered in Django (not currently requesting user)?

I tried this:

user = User.objects.get(username="jon")
if user.is_authenticated():
   print "user logged"

But this always returns Trueif matching username.

+3
source share
2 answers

There is no built-in method to accomplish what you are looking for, however there is an application that you can connect to your project that allows you to do what you want. It is called django-tracking, and you can find it here: https://github.com/codekoala/django-tracking

CHANGE! I beat him, but basically what Mark Lavigne said.

+1

: ; , - Django. , - , , , , . ( ) , . , , cookie ( 2 ).

? , , - , . , , 10 :

from datetime import datetime, timedelta
from django.contrib.auth.models import User

cutoff = datetime.now() - timedelta(minutes=10)
active = User.objects.filter(last_login__gt=cutoff)

, , . , , django-tracking.

+4

All Articles