Reputation: 322
DRF has permission_classes property on view. Method check_permissions instantiates every class in permission_classes list and calls has_permission(self, request, view) method to check whether user has permission to access this view.
All this methods are not static methods. They need instantiated view to check permissions.
Is there any way to check permissions statically, without instantiating view? Also, I don't want to copy&paste DRF code to do the same thing.
Something like this:
def check_permissions(view_class, request):
Upvotes: 0
Views: 189
Reputation: 322
There is no way to check view permissions without instantiating view. To omit instantiating hundreds of views on every request, I'm doing this once and saving result to user session.
Upvotes: 0
Reputation: 401
You can add your custom permissions from your settings file (usually settings.py
).
REST_FRAMEWORK = {
'DEFAULT_PERMISSION_CLASSES': (
'rest_framework.permissions.IsAuthenticated',
'permissions.custompermission.MyCustomPermissionClass',
),
......
}
If you do not know how to create permission classes, check the DRF tutorial. http://www.django-rest-framework.org/api-guide/permissions/#custom-permissions
Upvotes: 0