S
S
sazhyk2016-11-21 12:01:28
Django
sazhyk, 2016-11-21 12:01:28

How to get user in Django template?

How is it correct to get the username in the template?
So
{{ request.user.username }}
or so
{{ user.username }}
when connected

'OPTIONS': {
    'context_processors': [
        'django.template.context_processors.request',
    ],
},

On the Internet, there is such and such an implementation.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
P
Peter, 2016-11-21
@sazhyk

It's clear from the source code

#django.template.context_processors.request
def request(request):
    return {'request': request}

those. just passes the request variable to the template.
And in controllers you get the user through request.user
Means in the template also

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question