I noticed there are two ways to get a user object from request (assuming user is already logged in and the session is valid):
user = request.useruser = get_user(request) where get_user() is imported from django.contrib.auth.What's the difference? get_user() seems to do a lot of validation for request session.
Which is better?
request.user is actually populated with get_user(request).
It happens in AuthenticationMiddleware:
request.user = SimpleLazyObject(lambda: get_user(request))
So when you get request.user, you are actually getting get_user(request) result.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With