I need a link in django template which turns into logout if user is authenticated. (i have already implemented login/logout pages)
tried {% if user.is_authenticated %} {% endif %} and {% if user.is_anonymous %} {% endif %} but didn’t work.
Test Code (https://docs.djangoproject.com/en/dev/topics/auth/) –
{% if user.is_authenticated %}
<p>Welcome, {{ user.username }}. Thanks for logging in.</p>
{% else %}
<p>Welcome, new user. Please log in.</p>
{% endif %}
Returns false evan after logged in successfully.
It doesn’t look like there is anything wrong with the template code you posted. So I’d check out the associated view. In particular, if you’re using a custom-made view (rather than, say, a generic view), remember to supply a RequestContext to your template.
From the Django tutorial, part 4: