A Waffle Sample limits a new feature to a percentage of visitors. Wrap the feature in a conditional block, then let Django Waffle decide whether each call is active. This provides a small production audience for beta testing without exposing unfinished code to everyone. section 13.4
Use a Sample through this request flow:
- Install Django Waffle with `python -m pip install django-waffle`. section 13.4
- Add `waffle` to `INSTALLED_APPS`, add `waffle.middleware.WaffleMiddleware` to `MIDDLEWARE`, and run migrations for Waffle’s database tables. section 13.4
- Create a Sample in Django Admin and set its active percentage. section 13.4
- Call `sample_is_active()` with the Sample name and use its Boolean result to choose whether the feature runs. section 13.4
- Store the result when one view needs a consistent decision, because later calls generate a new random value. section 13.4
A sampled feature
Suppose a RiffMates view contains a new beta feature. Create a Sample configured for a percentage of visitors, then evaluate `sample_is_active("new-riff-feature")`. If it returns true, render the beta feature; otherwise, continue with the existing view behavior. Save that Boolean if the view checks the Sample more than once. section 13.4
