Reputation: 5
I'M new to Django, looking to get first name and last name of the logged-in user in Django, login method am using LDAP authentication.
when i login as admin i was able to see the LDAP user in User information tab.
Tried request.user.first_name didn't work, is there any other method to get the details?
Upvotes: 0
Views: 482
Reputation: 153
There is two method in AbstractUser class, you can use this
request.user.get_full_name()
request.user.get_short_name()
get_short_name will return first_name
Upvotes: 0
Reputation: 2084
You can use this method to get first name, last name and all details of the logged in user.
from django.contrib.auth.models import User
first_name = User.objects.get(username=request.user).first_name
last_name = User.objects.get(username=request.user).last_name
In the same way you can get any attribute of the user. For logged in users, you have to use the keyword request.user
.
Upvotes: 1