I have template like this :
<html>
<body>
You are logged as John Kowalski
</body>
</html>
I would like show first_name and last_name of user but this doesn’t work:
<html>
<body>
You are logged as {{ request.user.first_name }} {{ request.user.last_name }}
</body>
</html>
How can I get user object in template?
You need to do a few things:
First, add the following to your settings:
(You can add other context processors, but this is the relevant one.)
Second, in your views:
Import this:
And in your views, return your templates like this:
You can now access the
requestobject in your template.Learn more here: https://docs.djangoproject.com/en/dev/ref/templates/api/#subclassing-context-requestcontext