Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/mozmeao/django-allow-cidr
A Django Middleware to enable use of CIDR IP ranges in ALLOWED_HOSTS.
https://github.com/mozmeao/django-allow-cidr
Last synced: 1 day ago
JSON representation
A Django Middleware to enable use of CIDR IP ranges in ALLOWED_HOSTS.
- Host: GitHub
- URL: https://github.com/mozmeao/django-allow-cidr
- Owner: mozmeao
- License: other
- Created: 2018-02-16T18:41:24.000Z (almost 7 years ago)
- Default Branch: main
- Last Pushed: 2024-05-27T21:22:00.000Z (7 months ago)
- Last Synced: 2024-12-07T21:56:46.231Z (15 days ago)
- Language: Python
- Homepage:
- Size: 53.7 KB
- Stars: 99
- Watchers: 7
- Forks: 15
- Open Issues: 2
-
Metadata Files:
- Readme: README.rst
- Changelog: HISTORY.rst
- Contributing: CONTRIBUTING.rst
- License: LICENSE
- Code of conduct: CODE_OF_CONDUCT.md
- Authors: AUTHORS.rst
Awesome Lists containing this project
README
=============================
Django Allow CIDR
=============================.. image:: https://badge.fury.io/py/django-allow-cidr.svg
:target: https://badge.fury.io/py/django-allow-cidr.. image:: https://github.com/mozmeao/django-allow-cidr/actions/workflows/ci.yml/badge.svg
:target: https://github.com/mozmeao/django-allow-cidr/actionsA 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:
.. code-block:: python
MIDDLEWARE = (
'allow_cidr.middleware.AllowCIDRMiddleware',
...
)Add the ``ALLOWED_CIDR_NETS`` setting:
.. code-block:: 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 `netaddr`_ package.Running Tests
-------------Does the code actually work?
::
source /bin/activate
(myenv) $ pip install tox
(myenv) $ toxPushing 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`_.. _netaddr: https://netaddr.readthedocs.io/en/latest/
.. _Cookiecutter: https://github.com/audreyr/cookiecutter
.. _`cookiecutter-djangopackage`: https://github.com/pydanny/cookiecutter-djangopackage