Permissions in Django - has_perm()


Django tip:

You can check if a user has permission with the has_perm method:

user = User.objects.create_user(
    username="test",
    password="test",
    email="[email protected]"
)
print(user.has_perm("blog.view_post"))
# => False

superuser = User.objects.create_superuser(
    username="super",
    password="test",
   email="[email protected]"
)
print(superuser.has_perm("blog.view_post"))
# => True

For more, check out Permissions in Django.