Search code examples
pythondjangoauthenticationdjango-templatesrender-to-response

alternative to {% if request.user.is_active %} in Django Templates


What are the logic alternatives about:

{% if request.user.is_active %}

If the view doesn't return render_to_response with a dictionary with request, the template doesn't works properly.

So, any ideas are welcome.

//edited

my motivation is: when you work with views from installed apps, that you don't have the opportunity to modify them.


Solution

  • Add django.contrib.auth.context_processors.auth to TEMPLATE_CONTEXT_PROCESSORS in your settings.py.

    Now your have user variable in all your templates. So you can use this:

    {% if user.is_active %}
    

    See more in the docs: template context processors in settings, auth context processor.