Reputation: 2590
I'm currently limiting some urls to only logged-in users in Django by doing the following.
urls.py
urlpatterns = [
url(r'^$', login_required(views.MainView.as_view()), name='index')
]
Is there a way to limit urls to only admin and staff users except for regular users?
Upvotes: 1
Views: 73
Reputation: 16485
You can look into these two:
user_passes_test
decorator or also UserPassesTestMixin
permission_required
decorator or also the PermissionRequiredMixin
They should be sufficient for your needs. The docs show a few examples that fit your use case.
Upvotes: 1