The easiest way is to include django.contrib.auth.context_processors.auth in the TEMPLATE_CONTEXT_PROCESSORS configuration in settings.py . As described in the docs , add the user and perms to the context of your template, which will give you direct access to the current user.
Not that the default configuration for TEMPLATE_CONTEXT_PROCESSORS is (in Django 1.3):
("django.contrib.auth.context_processors.auth", "django.core.context_processors.debug", "django.core.context_processors.i18n", "django.core.context_processors.media", "django.core.context_processors.static", "django.contrib.messages.context_processors.messages")
So, the context processor must be active, and you must have access to the user variable in your templates without returning it to the view.
In your views, you can simply use the render shortcut, which will take care of creating the required instance of RequestContext:
from django.shortcuts import render def my_view(request): return render(request, 'template.html' )
source share