IP Authorisation Decorator

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
from decorator import decorator
from django.http import HttpResponse

#Simple decorator definition to authorize particular IPs in a view function

AUTHORIZED_IPS = ['192.168.101.100']

@decorator
def ip_authorization(func,*args,**kwargs):
    request = args[0]
    request_ip = request.META['REMOTE_ADDR']
    if request_ip in AUTHORIZED_IPS:
        return func(*args, **kwargs)
    else:
        return HttpResponse(status=401)

More like this

  1. IP Authorization Decorator with IP list by jansta 2 years, 3 months ago
  2. Internal view decorator by gsakkis 2 years, 10 months ago
  3. activation_required by offline 4 years, 11 months ago
  4. Test IP against IP address+Subnet whitelist by mtigas 3 years, 10 months ago
  5. view by view basic authentication decorator by Scanner 6 years ago

Comments

(Forgotten your password?)