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

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


An Alternative to

if user.is_anonymous():    # user is anon user

is by testing to see what the id of the user object is:

if user.id == None:    # user is anon userelse:    # user is a real user

see https://docs.djangoproject.com/en/dev/ref/contrib/auth/#anonymous-users


I know I'm doing a bit of grave digging here, but a Google search brought me to this page.

If your view def requires that the user is logged in, you can implement the @login_required decorator:

from django.contrib.auth.decorators import login_required@login_requireddef my_view(request):    …