A Django Middleware to enable use of CIDR IP ranges in ALLOWED_HOSTS.
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!
- The normal
ALLOWED_HOSTSvalues will also work as intended. This Middleware is intended to augment, not replace, the normal Django function. - If you do define
ALLOWED_CIDR_NETSand it has values, the middleware will capture what you have inALLOWED_HOSTS, setALLOWED_HOSTSto['*']and take over validation of host headers. - The
ALLOWED_CIDR_NETSvalues can be any valid network definition for the ipaddress library.
Does the code actually work?
source <YOURVIRTUALENV>/bin/activate (myenv) $ pip install tox (myenv) $ tox
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.
Tools used in rendering this package: