I'm attempting to create Django middleware that modifies the request object by adding additional data. I want to package this middleware so that it only requires the following steps for setup:
- Install via PIP
- Add route to
MIDDLEWARE
insettings.py
. - Read custom user settings from some config file.
I've been searching for ways to do this but have not found any. There are guides for creating middleware packages, but not for properly packaging them for distribution. So I have the following questions.
- Is it possible to install middleware via PIP?
- If this is possible, is there a good cookiecutter-like example to base it off of? I tried (https://github.com/pydanny/cookiecutter-djangopackage), but this assumes the package is a stand-alone app, which seems like overkill for a package that consists of a single class.
- What's the best way to allow a user to customize the behavior of the middleware object? Ideally, I'd like the user to pass in a callable with the custom behavior, but I'm not sure where a user can define custom settings/functionality that gets passed into the middleware upon instantiation.
Thanks in advance.