Guest User

Untitled

a guest
Jan 23rd, 2018
85
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.35 KB | None | 0 0
  1. from rest_framework import permissions
  2.  
  3. class BlacklistPermission(permissions.BasePermission):
  4. """
  5. Global permission check for blacklisted IPs.
  6. """
  7.  
  8. def has_permission(self, request, view):
  9. ip_addr = request.META['REMOTE_ADDR']
  10. blacklisted = Blacklist.objects.filter(ip_addr=ip_addr).exists()
  11. return not blacklisted
Add Comment
Please, Sign In to add comment