blfuentes
blfuentes

Reputation: 2827

Block url for users not in staff. Django

I would like to block some urls for users they don't have staff status.

Now I do it checking in my code in each def

if not request.user.is_staff:
    ...

But I have so many methods and all of them are under a /app/ path, so I thought perhaps exists a way to block for non staff users the access to those methods.

Thanks.

Upvotes: 1

Views: 1147

Answers (1)

Vic Smith
Vic Smith

Reputation: 3497

Use the staff_member_required decorator:

from django.contrib.admin.views.decorators import staff_member_required

@staff_member_required

EDIT: Code is here if you need it.

Upvotes: 4

Related Questions