Skip to main content
Pre-release

This release is a pre-release and may not be stable for production use.

https://badge.fury.io/py/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 netaddr package.

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

0.8.0 (2025-XX-XX)

  • Confirm Django 5.0, 5.1, and 5.2 support.

  • Confirm Python 3.12 and 3.13 support.

  • Drop support for Python 3.7.

  • Drop support for Django < 4.2.

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.

Download files

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

Source Distribution

django_allow_cidr-0.8.0rc0.tar.gz (7.0 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

django_allow_cidr-0.8.0rc0-py2.py3-none-any.whl (5.0 kB view details)

Uploaded Python 2Python 3

File details

Details for the file django_allow_cidr-0.8.0rc0.tar.gz.

File metadata

  • Download URL: django_allow_cidr-0.8.0rc0.tar.gz
  • Upload date:
  • Size: 7.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.12.8

File hashes

Hashes for django_allow_cidr-0.8.0rc0.tar.gz
Algorithm Hash digest
SHA256 6b5583daff34ae602d66f4de88db011e6995acb90d95297456c0cbb452b6d423
MD5 f311267054099b42833212955047cb85
BLAKE2b-256 e2d74d921a5cfabb82d818abbac54f170d3a157b2982e83c026569da99f0ce8a

See more details on using hashes here.

File details

Details for the file django_allow_cidr-0.8.0rc0-py2.py3-none-any.whl.

File metadata

File hashes

Hashes for django_allow_cidr-0.8.0rc0-py2.py3-none-any.whl
Algorithm Hash digest
SHA256 4f8c33882ba3c728dfe9c0f6ff3683bf781768201c0a5df35e0905a3f0572a1f
MD5 f71fef634c5f8a19e287940dcf0cc093
BLAKE2b-256 7b640dd4b40e67f584ea7be1fc058b2b4b9c6f3aec834a28ef76e2ea6bc08a30

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page