Reputation: 12466
If the user anonymous or not, how can i check that in base.html?
Which is correct?
{% if request.user.is_authenticated %}
Or
{% if user.is_authenticated %}
How can i pass the variable request.user
in base.html?
Upvotes: 1
Views: 1136
Reputation: 92617
Try using the Request context:
from django.template import RequestContext
# in a view
return render_to_response('base.html', context_instance = RequestContext(request))
Make sure you take a look at these context processors: https://docs.djangoproject.com/en/dev/ref/templates/api/#django-contrib-auth-context-processors-auth
And then you should be able to access user
in your templates
You can use the django shortcut render
to always render a template that is automatically passed a RequestContent:
https://docs.djangoproject.com/en/dev/topics/http/shortcuts/#module-django.shortcuts
Upvotes: 1