Skip to content

Instantly share code, notes, and snippets.

@nferrari
Created November 4, 2014 11:15
Show Gist options
  • Save nferrari/2762af8bf101ed1e077a to your computer and use it in GitHub Desktop.
Save nferrari/2762af8bf101ed1e077a to your computer and use it in GitHub Desktop.
django-rest-framework read-only permission class
from rest_framework import permissions
class IsReadOnly(permissions.BasePermission):
"""
Object-level permission to only allow read-only operations.
"""
def has_permission(self, request, view):
# Read permissions are allowed to any request,
# so we'll always allow GET, HEAD or OPTIONS requests.
if request.method in permissions.SAFE_METHODS:
return True
@wmabebe
Copy link

wmabebe commented Oct 13, 2016

return request.method in permissions.SAFE_METHODS

👍

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment