How do I check whether this user is anonymous or actually a user on my system?

TIMEX picture TIMEX · Jan 10, 2011 · Viewed 42.2k times · Source
def index(request):
    the_user = request.user

In Django, how do I know if it's a real user or not? I tried:

if the_user: but "AnonymousUser" is there even if no one logs in. So, it always returns true and this doesn't work.

Answer

Daniel DiPaolo picture Daniel DiPaolo · Jan 10, 2011

You can check if request.user.is_anonymous returns True.