What's the best way to get user information from a django template?
For example, if I just want to:
I'm using django-registration/authentication
An alternate method for current Django versions:
{% if user.is_authenticated %}
<p>Welcome, {{ user.get_username }}. Thanks for logging in.</p>
{% else %}
<p>Welcome, new user. Please log in.</p>
{% endif %}
Note:
request.user.get_username()
in views & user.get_username
in templates. Preferred over referring username
attribute directly. Sourcedjango.contrib.auth.context_processors.auth
is enabled by default & contains the variable user django.core.context_processors.request
template context processor.Source : https://docs.djangoproject.com/en/dev/topics/auth/default/#authentication-data-in-templates