Search code examples
djangodjango-templatesdjango-context

Is it possible automatically include user to all templates?


I have project in Django 1.3. In order to show username in all pages I use such tags in base.html

{% if user.is_authenticated %}
    <p>Welcome, {{ user.username }}.  
    <a href="/proc/accounts/logout/">loggout</a></p>
{% else %}
    <a href="/proc/accounts/login/">loggin</a>
{% endif %}

But if I dont return context_instance=RequestContext(request) from view value of user in template is empty. The 'django.contrib.auth.context_processors.auth' is included to TEMPLATE_CONTEXT_PROCESSORS.

Is it possible automaticaly include user to all templates?


Solution

  • since django 1.3. use shortcuts.render function and dont warry about requestcontext including to your views