1 2 3 4 5 6 7 8 9 10 11 12 | """
simple middlware to block IP addresses via settings variable BLOCKED_IPS
"""
from django.conf import settings
from django import http
class BlockedIpMiddleware(object):
def process_request(self, request):
if request.META['REMOTE_ADDR'] in settings.BLOCKED_IPS:
return http.HttpResponseForbidden('<h1>Forbidden</h1>')
return None
|
More like this
- SQL Printing Middleware by ericflo 5 years, 11 months ago
- Mobilize your Django site by stevena0 4 years, 1 month ago
- Tuned IPAddressField with IPv4 & IPv6 support by diverman 4 years, 2 months ago
- Basic Auth Middleware by joshsharp 1 year, 11 months ago
- Another Cookieless Session Middleware by lvscar 3 years, 11 months ago
Comments