Reputation: 43
As mentioned in the documentation, authenticated user's object is stored within user variable in templates. i need where django stored user variable in apps file thanks:
user = request.user
request['user'] = user #where is?
thanks for help
Upvotes: 1
Views: 389
Reputation: 9801
It's in the AuthenticationMiddleware
.
The official doc mentioned it:
link:
AuthenticationMiddleware associates users with requests using sessions.
link:
class AuthenticationMiddleware
Adds the user attribute, representing the currently-logged-in user, to every incoming HttpRequest object. See Authentication in Web requests.
source code(django.contrib.auth.middleware.py):
class AuthenticationMiddleware(object):
def process_request(self, request):
assert hasattr(request, 'session'), "The Django authentication middleware requires session middleware to be installed. Edit your MIDDLEWARE_CLASSES setting to insert 'django.contrib.sessions.middleware.SessionMiddleware'."
request.user = SimpleLazyObject(lambda: get_user(request))
Upvotes: 2
Reputation: 369274
Make sure you're using RequestContext
. Otherwise user
is not available in the templates.
Upvotes: 1