A Django Middleware to enalbe use of CIDR IP ranges in ALLOWED_HOSTS.
Project description
A Django Middleware to enalbe 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 ALLOW_CIDR_NETS setting:
ALLOW_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 ALLOW_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 ALLOW_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
Credits
Tools used in rendering this package:
History
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
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
File details
Details for the file django-allow-cidr-0.3.0.tar.gz
.
File metadata
- Download URL: django-allow-cidr-0.3.0.tar.gz
- Upload date:
- Size: 5.5 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 63436f3820dd788863ef35f4fad5499f5ad23063b52033b03afdb1df7929797f |
|
MD5 | 34e7477a7ab08e89cf39635eae78697f |
|
BLAKE2b-256 | 9ca13895d29ca91e3ee353e5baf5621f880c5057ffc1609aa6c3bf87a0a8fbb1 |
File details
Details for the file django_allow_cidr-0.3.0-py2.py3-none-any.whl
.
File metadata
- Download URL: django_allow_cidr-0.3.0-py2.py3-none-any.whl
- Upload date:
- Size: 6.0 kB
- Tags: Python 2, Python 3
- Uploaded using Trusted Publishing? No
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | f19558a27ea558ad2174d15874f8eaf36d9e50e16587c7558d2a3bdc69c0d3bb |
|
MD5 | 6887d86c81e90bdba801d3bd1604422e |
|
BLAKE2b-256 | 53908498bb8302ee6aa012b4d97e03d3e6a0ab12218740a52003fc430c01e115 |