0

In my website, I can't display the user.fname. Everything else in user, like user.username, user.email, and user.password work, but i cant display the name.

PS: ive tried user.fname, user.name, user.name, user.first_name so far, none display anything

EDIT:

user = request.user
if request.user.is_authenticated():
    fname = request.user.get_short_name()
return render(request, 'student/dashboard.html', {'user': user, 'fname': fname})

I added this, but i still cant call it for some reason (this is my views)

class RegisterForm(forms.Form):
        GRADE_CHOICES = ( 
                    (9,'9'), (10,'10'), (11,'11'), (12,'12') , 
                )
        curr_year = date.today().year
        GRAD_YEAR_CHOICES = ( 
                    (curr_year,curr_year), (curr_year+1,curr_year+1), (curr_year+2,curr_year+2), (curr_year+3,curr_year+3) , 
                     )
        fname = forms.CharField(max_length = 25)
        lname = forms.CharField( max_length = 25)
        emailid = forms.EmailField()
        passwd1 = forms.CharField(max_length=100,widget=forms.PasswordInput)
        passwd2 = forms.CharField(max_length=100,widget=forms.PasswordInput)
        gradyear = forms.ChoiceField( choices=GRAD_YEAR_CHOICES)
        grade = forms.ChoiceField( choices=GRADE_CHOICES)

This is in my forms.py

Abhishek Patel
  • 587
  • 2
  • 8
  • 25

1 Answers1

0

Try

 user.first_name
 user.last_name

if the user is already loggedin you can use in your views:

if request.user.is_authenticated():
    username = request.user.get_username()

more info: https://docs.djangoproject.com/en/1.8/ref/contrib/auth/

WayBehind
  • 1,607
  • 3
  • 39
  • 58