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
- IP Authorization Decorator with IP list by jansta 2 years, 3 months ago
- Internal view decorator by gsakkis 2 years, 10 months ago
- activation_required by offline 4 years, 10 months ago
- Test IP against IP address+Subnet whitelist by mtigas 3 years, 10 months ago
- view by view basic authentication decorator by Scanner 6 years ago
Comments