Django Waffle is a feature-flag library for exposing new functionality to selected visitors instead of releasing every change to everyone at once. Wrap the new code in a conditional block, then let controlled users beta-test it in production. section 13.4
Waffle provides three controls: switches, samples, and flags. A switch is an on–off setting, a sample enables a feature for a percentage of visitors, and a flag applies finer-grained visitor targeting. section 13.4 section 13.6
Set up Django Waffle with the normal Django project conventions:
- Install the package with `python -m pip install django-waffle`. section 13.4
- Add `waffle` to `INSTALLED_APPS` and `waffle.middleware.WaffleMiddleware` to `MIDDLEWARE`. section 13.4
- Run the `migrate` command because Waffle stores its state in database tables. section 13.4
Choosing a control
Use the Django Admin or a management tool to create and manage switches and samples. In application code, call `switch_is_active()` with the Switch name and use its Boolean result to guard the feature. Call `sample_is_active()` for percentage-based exposure; each call can produce a new Boolean result. Use a flag when visibility depends on visitor details such as role, account, language, or group. section 13.4 section 13.6
