Showing the logged-in user inside base.html (django)

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 %}

Answers


request.user gives 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 the first_name, you can do {{ request.user.first_name }}. To get the full name you use {{ request.user.get_full_name }}.


Need Your Help

best practices with sessions -login

php session login

i have a system with a login. Then, the user made the login and he have access to private stuff (personal data).

EWS get Contacts - CustomerID & Account

c# contacts ews exchangewebservices

ExchangeService service = this.GetService();