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.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.2.0.tar.gz
.
File metadata
- Download URL: django-allow-cidr-0.2.0.tar.gz
- Upload date:
- Size: 5.4 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 9c8f1202554922c6824b73d3d37331b37181b180b3ea72b17188ae33100b99cd |
|
MD5 | 9ad344dc8b7bb3716d9661e25d438bbf |
|
BLAKE2b-256 | bdb6f22f66533c96d900804f3de27c0d61bc68977818a932c16dd35bc2850675 |
File details
Details for the file django_allow_cidr-0.2.0-py2.py3-none-any.whl
.
File metadata
- Download URL: django_allow_cidr-0.2.0-py2.py3-none-any.whl
- Upload date:
- Size: 5.9 kB
- Tags: Python 2, Python 3
- Uploaded using Trusted Publishing? No
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 222d83b1a4da16f81ce6e2ed982c657e9e8e8cfe9c68527ab16a18679c4de56c |
|
MD5 | c77c0b8db35a7b5dc4de97308d5de082 |
|
BLAKE2b-256 | 0f957181a2477324feeeeea977d77a365ae21a439b5c9d75a133e275bfd1a8d2 |