---
title: "django-allow-cidr | pypx"
description: "A Django Middleware to enable use of CIDR IP ranges in ALLOWED_HOSTS."
canonical_url: "https://pypx.app/packages/django-allow-cidr"
meta:
  "og:description": "A Django Middleware to enable use of CIDR IP ranges in ALLOWED_HOSTS."
  "og:image": "https://pypx.app/_og/d/h_630%2Cc_PackageCard%2Cname_django-allow-cidr%2Cversion_0.8.0%2Csummary_A%2BDjango%2BMiddleware%2Bto%2Benable%2Buse%2Bof%2BCIDR%2BIP%2Branges%2Bin%2BALLOWED__HOSTS.%2Clicense_Apache%2BSoftware%2BLicense%2Cp_Ii9wYWNrYWdlcy9kamFuZ28tYWxsb3ctY2lkciI%2Cs_gVUPd7lF4XO8QjBE.png"
  "og:image:height": "630"
  "og:image:type": image/png
  "og:image:width": "1200"
  "og:title": "django-allow-cidr 0.8.0"
  "twitter:image": "https://pypx.app/_og/d/h_630%2Cc_PackageCard%2Cname_django-allow-cidr%2Cversion_0.8.0%2Csummary_A%2BDjango%2BMiddleware%2Bto%2Benable%2Buse%2Bof%2BCIDR%2BIP%2Branges%2Bin%2BALLOWED__HOSTS.%2Clicense_Apache%2BSoftware%2BLicense%2Cp_Ii9wYWNrYWdlcy9kamFuZ28tYWxsb3ctY2lkciI%2Cs_gVUPd7lF4XO8QjBE.png"
---

> Index of every page on this site: [llms.txt](https://pypx.app/llms.txt)

# **django-allow-cidr**

v0.8.0

A Django Middleware to enable use of CIDR IP ranges in ALLOWED\_HOSTS.

5 KBpy2.py3-none-anyApache Software License1 deps

[**Diff **](https://pypx.app/packages/django-allow-cidr/diff)

`$ uv add django-allow-cidr`

# Django Allow CIDR

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:

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

Add the ALLOWED\_CIDR\_NETS setting:

```python
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:

- Cookiecutter\_
- `cookiecutter-djangopackage`\_

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

## **Details **

<dl>

<dt>Version</dt>
<dd>0.8.0</dd>

<dt>License</dt>
<dd>Apache Software License</dd>

<dt>Maintainer</dt>
<dd>Paul McLanahan</dd></dl>

## **Links**

- [Homepage](https://github.com/mozmeao/django-allow-cidr)
- [View on PyPI](https://pypi.org/project/django-allow-cidr/)

## **Maintainers **

- Paul McLanahan · [pmac@mozilla.com](mailto:pmac@mozilla.com)

```json
{"@context":"https://schema.org","@graph":[{"@id":"https://pypx.app/#website","@type":"WebSite","description":"The Python Package Index, reimagined. Fast search, dependency insights, download trends, and changelogs — all in one place.","name":"pypx","url":"https://pypx.app/"},{"@id":"https://pypx.app/packages/django-allow-cidr#webpage","@type":"WebPage","description":"A Django Middleware to enable use of CIDR IP ranges in ALLOWED_HOSTS.","name":"django-allow-cidr","url":"https://pypx.app/packages/django-allow-cidr","isPartOf":{"@id":"https://pypx.app/#website"},"potentialAction":[{"@type":"ReadAction","target":["https://pypx.app/packages/django-allow-cidr"]}]},{"@id":"https://pypx.app/packages/django-allow-cidr#/schema/software-application/1","@type":"SoftwareApplication","applicationCategory":"DeveloperApplication","description":"A Django Middleware to enable use of CIDR IP ranges in ALLOWED_HOSTS.","license":"Apache Software License","name":"django-allow-cidr","softwareVersion":"0.8.0"}]}
```

## Sitemap

See the full [sitemap](https://pypx.app/sitemap.md) for all pages.
