{% if user.is_authenticated %} for specific user only

Viewed 359

I am using : {% if user.is_authenticated %} to check if people are logged in, so I can set the navbar links depending on logged in or not.

I want to make navbar links special for admin user. So there has to be a check not just if that user is authenticated, but also if that authenticated user is an Admin.

I was thinking about something like {% if user(Admin).is_authenticated %} but that didn't work.

Somebody got an idea?

3 Answers

Django uses .is_staff and .is_superuser for these checks. See more details here. is_superuser checks the boolean field in the django user module.

try

{% if user.is_superuser %}

Just extend your condition

{% if user.is_authenticated and user.is_admin %}

You can

    {% if usr.is_superuser %}
    Do something here for the superuser
    {% endif %}
    {% if usr.is_authenticated %}
    Do something for those who are authenticated
    {% else %}
    Do something for those who did not authenticate
    {% endif %}
Related