Burak
Burak

Reputation: 5764

In Django, how to restrict some url access depending on users' groups?

In my Django application, I have 3 types of roles(groups)

Superuser AccountAdmin ShopAdmin

I want that, superuser can access to every url, but other 2 admins cannot access /su/* urls.

How can I do that?

Upvotes: 4

Views: 5992

Answers (1)

DrTyrsa
DrTyrsa

Reputation: 31951

from django.contrib.auth.decorators import user_passes_test

@user_passes_test(lambda u: u.is_superuser)
def your_su_view(request):
    pass

Upvotes: 5

Related Questions