A Django middleware to restrict the access to the Django admin based on incoming IPs
Requirements
Python >= 3.10
Django >= 4.0
django-ipware >= 7
Usage
First install the package:
$ pip install django-admin-ip-restrictor
Then add the middleware to your settings:
MIDDLEWARE = [
...
'admin_ip_restrictor.middleware.AdminIPRestrictorMiddleware'
]
Set these variables in your settings.py to control who has access to the admin (IPV4 and IPV6 can be mixed):
RESTRICT_ADMIN=True ALLOWED_ADMIN_IPS=['127.0.0.1', '::1'] ALLOWED_ADMIN_IP_RANGES=['127.0.0.0/24', '::/1'] RESTRICTED_APP_NAMES=['admin'] TRUST_PRIVATE_IP=True
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='127.0.0.1,::1' $ export ALLOWED_ADMIN_IP_RANGES='127.0.0.0/24,::/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.
Changelog
Full changelog at https://github.com/sdonk/django-admin-ip-restrictor/blob/master/CHANGELOG.rst
Run tests
Install uv (https://docs.astral.sh/uv/getting-started/installation/) then run:
$ uv run tox
Contribute
Fork the project and submit a PR!
Metadata
Release files for django-admin-ip-restrictor 3.0.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | |
|---|---|---|---|---|
| django_admin_ip_restrictor-3.0.0.tar.gz | 38.2 kB | With provenance | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| django_admin_ip_restrictor-3.0.0-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 42.4 kB
Release files / django_admin_ip_restrictor-3.0.0.tar.gz
| Download URL | django_admin_ip_restrictor-3.0.0.tar.gz |
|---|---|
| Size | 38.2 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
5f4beba0a0fd6f1e3501cb2ed711b3a36c7056a009ab5b55db6c95ba99bb97e7
|
|
BLAKE2b-256 checksum How to use checksums |
340d1e42b3f6ed97621b0501ec04bdce4cb4e912f83fc5ca8192a8d4cc01b23e
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/6.1.0 CPython/3.13.7
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Mar 10, 2026.
Transparency logRelease files / django_admin_ip_restrictor-3.0.0-py3-none-any.whl
| Download URL | django_admin_ip_restrictor-3.0.0-py3-none-any.whl |
|---|---|
| Size | 4.2 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
68c0094539504c4f6570b90aa79072862369ea24555b946cc79e58aaa35af7f7
|
|
BLAKE2b-256 checksum How to use checksums |
d7a7dc1d9aeadb66274c9953888be4e23c7c9183df5997bee2be61b87f33dcc5
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/6.1.0 CPython/3.13.7
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Mar 10, 2026.
Transparency logSecurity for django-admin-ip-restrictor 3.0.0
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
Full provenance
All 2 files in this release have been uploaded with provenance metadata.
Attestation for django_admin_ip_restrictor-3.0.0.tar.gz
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Mar 10, 2026.
Transparency logA note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.