city
city

Reputation: 261

Why is the logged in user not detected with 'user.is_authenticated' in my template?

In my template I have

{% if user.is_authenticated %}
<li><a href="http://127.0.0.1:8000/logout/">Logout</a></li>
{% endif %}

which adds a button to the nav bar if the user is logged in. the code works for all the views that have @login_required or @permission_required but it doesn't recognize the user if they travel a page that allows but logged in users and anonymous users. Any idea why why this is and/or how to fix it?

Upvotes: 0

Views: 95

Answers (1)

agf
agf

Reputation: 176780

You need to have:

django.contrib.auth.context_processors.auth

your context processors in settings.py, and you need to pass

RequestContext

to the view, in order to have user in your context.

Upvotes: 1

Related Questions