Skip to main content

Django Allow CIDR

https://img.shields.io/pypi/v/django-allow-cidr.svg https://github.com/mozmeao/django-allow-cidr/actions/workflows/ci.yml/badge.svg

A Django Middleware to enable use of CIDR IP ranges in ALLOWED_HOSTS.

Quickstart

Install Django Allow CIDR:

pip install django-allow-cidr

Add the Middleware to your MIDDLEWARE settings. It should be the first in the list:

MIDDLEWARE = (
    'allow_cidr.middleware.AllowCIDRMiddleware',
    ...
)

Add the ALLOWED_CIDR_NETS setting:

ALLOWED_CIDR_NETS = ['192.168.1.0/24']

Profit!

Features

  • The normal ALLOWED_HOSTS values will also work as intended. This Middleware is intended to augment, not replace, the normal Django function.

  • If you do define ALLOWED_CIDR_NETS and it has values, the middleware will capture what you have in ALLOWED_HOSTS, set ALLOWED_HOSTS to ['*'] and take over validation of host headers.

  • The ALLOWED_CIDR_NETS values can be any valid network definition for the ipaddress library.

Running Tests

Does the code actually work?

source <YOURVIRTUALENV>/bin/activate
(myenv) $ pip install tox
(myenv) $ tox

Pushing to PyPI

Cutting a new Github Release will trigger CI checks, followed by an automatic release to PyPI, using the release version. Please make sure that your Github Release version matches the project version in __init__.py.

For more details see the release job in .github/workflows/ci.yml.

Credits

Tools used in rendering this package:

History

Unreleased

No unreleased changes

0.8.0 (2025-04-08)

  • Add Django 5.2 to test matrix and remove EOL versions

  • Drop support for Python <3.9 and add 3.13 to CI

0.7.1 (2023-07-10)

  • Update setup.cfg to rename deprecated licence_file param

0.7.0 (2023-07-10)

  • Add IPv6 support - thanks @rissson!

  • Add Django 4.2 to CI; freshen up CI config

0.6.0 (2023-01-05)

  • Drop dev-related dependencies (incl vulnerable version of wheel, which was not installed in general use)

  • Remove redundant code from setup.py now we’re auto-publishing via Github

  • Update testing matrix: Drop Python 3.6; add Python 3.11; add Django 4.1

0.5.0 (2022-07-09)

  • Replace the netaddr dependency with Python 3’s ipaddress - thanks @n1ngu!

  • Update GH actions to release to PyPI

0.4.1 (2022-06-13)

  • Use packaging.version to avoid distutils deprecated module - thanks @adamantike!

0.4.0 (2022-02-22)

  • Drop Django support for non-LTS and non-latest Django (so, removing 1.x, 2.0, 2.1, 3.0, 3.1)

  • Drop support for older Python releases (2.x, 3.5)

  • Add Django 4.0 to tox’s test matrix

  • Add Python 3.7 through 3.10 to tox’s test matrix; 3.6 to 3.10 are now the only tested versions

  • Switch CI to Github Actions

0.3.1 (2018-07-31)

  • Fix issue #6: Accept passed in get_response function for Middleware in Django >= 1.10.

  • Publish updated docs that fix the ALLOWED_CIDR_NETS typo.

0.3.0 (2018-02-21)

  • Disable middleware if ALLOWED_HOSTS is set to [‘*’].

0.2.0 (2018-02-21)

  • Handle host names with ports (Thanks Giorgos!).

0.1.0 (2018-02-16)

  • First release on PyPI.

Metadata

Release files for django-allow-cidr 0.8.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for django-allow-cidr 0.8.0
File Size Uploaded Provenance Actions
django_allow_cidr-0.8.0.tar.gz 7.0 kB Without provenance Details for django_allow_cidr-0.8.0.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for django-allow-cidr 0.8.0
File Interpreter ABI Platform Actions
django_allow_cidr-0.8.0-py2.py3-none-any.whl Python 2, Python 3 none any Details for django_allow_cidr-0.8.0-py2.py3-none-any.whl

Total release size: 12.0 kB

Release files / django_allow_cidr-0.8.0.tar.gz

Download URL django_allow_cidr-0.8.0.tar.gz
Size 7.0 kB
Tags Source
SHA-256 checksum
How to use checksums
d6f80230621dd5b19ec1665b85abf8218b02556ff7cf0ddda41e2607267a3277
BLAKE2b-256 checksum
How to use checksums
12e0d811149809b1e4cb2daf357b44b71f240feea0718549b0a2ab2af3c4f63f
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.1.0 CPython/3.12.8

Release files / django_allow_cidr-0.8.0-py2.py3-none-any.whl

Download URL django_allow_cidr-0.8.0-py2.py3-none-any.whl
Size 5.0 kB
Tags Python 2 Python 3
SHA-256 checksum
How to use checksums
724ce76b7b4a25c641ddcd33777e2e95da622dd2c11937f0d76d0cd3d54b1622
BLAKE2b-256 checksum
How to use checksums
992a10ebaba1950c113efae2b38dc5e1ec38a86e1141e97b7e729f2fb4bbb87b
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.1.0 CPython/3.12.8

Security for django-allow-cidr 0.8.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.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A 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.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page