Skip to main content

A Django middleware to restrict incoming IPs to admin panel

Project description

A Django middleware to restrict the access to the Django admin based on incoming IPs


  • Python >= 3.5
  • Django >= 1.11,<3
  • django-ipware=>2,<3


First install the package:

$ pip install django-admin-ip-restrictor

Then add the middleware to your settings:


Set these variables in your to control who has access to the admin (IPV4 and IPV6 can be mixed):


Use RESTRICTED_APP_NAMES to restrict the access to more apps. Admin app is always included.

If using environment variables make sure that the variables receive the right type of value. django-admin-ip-restrictor automatically converts the following formats:

$ export RESTRICT_ADMIN='true'
$ export ALLOWED_ADMIN_IPS=',::1'
$ export ALLOWED_ADMIN_IP_RANGES=',::/1'
$ export RESTRICTED_APP_NAMES='wagtail_admin,foo'

For RESTRICT_ADMIN also these values can be used: True, 1, false, False, 0

Use TRUST_PRIVATE_IP to skip checking IP addresses from a trusted private network.

Run tests

Install tox:

$ pip install tox

Install pyenv, use as reference.

Install Python versions in pyenv:

$ pyenv install 3.5.9
$ pyenv install 3.6.10
$ pyenv install 3.7.6
$ pyenv install 3.8.1

Specify the Python versions you want to test with:

$ pyenv local 3.5.9 3.6.10 3.7.6 3.8.1

Run tests:

$ tox


Fork the project and submit a PR!

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Files for django-admin-ip-restrictor, version 2.1.1
Filename, size File type Python version Upload date Hashes
Filename, size django-admin-ip-restrictor-2.1.1.tar.gz (4.6 kB) File type Source Python version None Upload date Hashes View hashes

Supported by

Elastic Elastic Search Pingdom Pingdom Monitoring Google Google BigQuery Sentry Sentry Error logging AWS AWS Cloud computing DataDog DataDog Monitoring Fastly Fastly CDN DigiCert DigiCert EV certificate StatusPage StatusPage Status page