In my template, I have the following:
<ul class="tabbed" id="network-tabs">
{% if user.is_authenticated %}
<li><a href="{% url acct-my-profile %}">My Account</a></li>
<li><a href="{% url acct-logout %}">Log Out</a></li>
{% else %}
<li><a href="{% url acct-login %}">Log in</a></li>
<li><a href="{% url acct-register %}">Register</a></li>
{% endif %}
</ul>
It seems to work fine, unless the page been created has a @login_required decorator, in which case the page works fine but the navigation appears as if the user is not logged in, even when they are.
You should check your view function to see where the
uservariable is coming from. Unless you’re specifically passinguserinto the context from the view, that’s your problem.You do have access to
request.user, though, and that will always return true in a template rendered from a view that has the@login_requireddecorator.The reason I can tell you for certain that there’s nothing wrong with the decorator, though, is that in the code for
UserandAnonymousUser(located indjango.contrib.auth.models) theis_authenticatedmethod strictly returns true forUserand false forAnonymousUser. The decorator does not and cannot change that. And what that means is that your template isn’t actually getting aUserobject where you’re checkinguser.