On 10/4/05, Jacob Kaplan-Moss <[EMAIL PROTECTED]> wrote: > On Oct 4, 2005, at 8:42 AM, Andreas wrote: > > What's the best way to check if a user is logged in on every page > > (read: view) of a website? I'd like to be able to display the username > > in the template if a user is logged in. At the moment, I'm using the > > following code: > > If you use django.core.extensions.DjangoContext instead of > django.core.template.Context the {{ user }} variable will > automatically be available in your templates. If > {{ user.is_anonymous }} is True then the user is *not* logged in; > otherwise the user info is available as {{ user.username }}, > {{ user.email }}, etc.
A quick addition -- note that you can also do this in the view: def foo_view(request): if request.user.is_anonymous(): # Do something for anonymous users else: # Do something for logged-in users Adrian -- Adrian Holovaty holovaty.com | djangoproject.com | chicagocrime.org