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)