django check if user is admin

You can check if a user is an admin in Django by following these steps:

Step 1: Import the necessary module

from django.contrib.auth.decorators import user_passes_test

Step 2: Define a function to check if the user is an admin

def is_admin(user):
    return user.is_authenticated and user.is_superuser

Step 3: Apply the user_passes_test decorator to your view function

@user_passes_test(is_admin)
def your_view_function(request):
    # Your view function logic here