How get current user in a template tag?

If you want to access the current user in a template tag, you must pass it as a parameter in the templates, like so:

{% my_template_tag user %}

Then make sure your template tag accepts this extra parameter. Check out the documentation on this topic. You should also check out simple tags.


The user is always attached to the request, in your templates you can do the following:

{% if user.is_authenticated %}
{% endif %}

You don't have to specify "request" to access its content

UPDATE:

Be aware: is_authenticated() always return True for logged user (User objects), but returns False for AnonymousUser (guest users). Read here: https://docs.djangoproject.com/en/1.7/ref/contrib/auth/