Get user information in django templates
问题 What's the best way to get user information from a django template? For example, if I just want to: If the user is logged in, display "Welcome [username]" Otherwise, display the login button. I'm using django-registration/authentication 回答1: 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: Use request.user.get_username() in views