A Django Middleware to enable use of CIDR IP ranges in ALLOWED_HOSTS.
Project description
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_CLASSES (for Django < 1.10) or 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
History
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.
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Filename, size | File type | Python version | Upload date | Hashes |
---|---|---|---|---|
Filename, size django_allow_cidr-0.3.1-py2.py3-none-any.whl (4.1 kB) | File type Wheel | Python version py2.py3 | Upload date | Hashes View |
Filename, size django-allow-cidr-0.3.1.tar.gz (5.6 kB) | File type Source | Python version None | Upload date | Hashes View |
Close
Hashes for django_allow_cidr-0.3.1-py2.py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | e8708c0511a78b80d9b74f718ee46685a1425e6d3520143bd00c773fdca56cc7 |
|
MD5 | 25bd4aef028ddb462e7ce7af6e9abed0 |
|
BLAKE2-256 | 19284030e333a2100b73962fb9ff7fac85567168c45aa01f3df76e8f729c8924 |