Simple middleware, to ban users by IP or to ban IP networks.
Switch branches/tags
Nothing to show
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Failed to load latest commit information.
django_ban Initial commit. Oct 16, 2008
LICENSE Initial commit. Oct 16, 2008 Small fixes in the README. Oct 16, 2008


This is a simple application to restrict access to site by IP.


  • Install ipcalc library.

  • Add django_ban in you INSTALLED_APPS.

  • Add option BAN_POLICY:
    BAN_POLICY = 'deny,allow' or BAN_POLICY = 'allow,deny'.

    In first case it means that all users are allowed by default, second case restricts access to all users who not in allow list

    Default value is 'allow,deny'

  • Add 'django_ban.middleware.Ban' to your MIDDLEWARE_CLASSES.

  • Run ./ syncdb, to create necessary tables.

  • Add one or more entries to the Allow or Deny lists in the admin interface. You can just enter a single IP or use a network mask, like this:



  • Add a text description to the list items.
  • Use html template to render Deny page.


This application is based on the Justquick's django snippet. You can find the original code at