Created
September 10, 2014 14:27
-
-
Save arthuralvim/9771f75e3f16ba5daafb to your computer and use it in GitHub Desktop.
Django Rest Framework - Only ajax requests are permitted.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from rest_framework.permissions import BasePermission | |
class IsAjaxPermission(BasePermission): | |
""" | |
Check is request is ajax. | |
""" | |
def has_object_permission(self, request, view, obj): | |
return request.is_ajax() | |
def has_permission(self, request, view): | |
return request.is_ajax() | |
# if you want to fake it, just put in the request header 'HTTP_X_REQUESTED_WITH'='XMLHttpRequest' | |
# from django.http.request.py | |
# def is_ajax(self): | |
# return self.META.get('HTTP_X_REQUESTED_WITH') == 'XMLHttpRequest' |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment