Block IP addresses

 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

  1. SQL Printing Middleware by ericflo 5 years, 11 months ago
  2. Mobilize your Django site by stevena0 4 years, 1 month ago
  3. Tuned IPAddressField with IPv4 & IPv6 support by diverman 4 years, 2 months ago
  4. Basic Auth Middleware by joshsharp 1 year, 11 months ago
  5. Another Cookieless Session Middleware by lvscar 3 years, 11 months ago

Comments

(Forgotten your password?)