Is there a way to access the logged in user’s firstname inside the base.html file?
I’m trying to do this, because i want to display who is currently logged in on the navigation bar, but it won’t access the user’s information, nor will it correctly check if the user is authenticated.
html inside base.html
Hi there,
{% if user.is_authenticated %}
{{user.first_name}}
{% else %}
Stranger
{% endif %}
request.usergives you the user object that is currently logged in. So you have full access to all the attributes and methods the User class has. To get thefirst_name, you can do{{ request.user.first_name }}. To get the full name you use{{ request.user.get_full_name }}.