liveBook · Manning

Django Waffle

As explained in Django in Action

Django Waffle is a Django package for controlling feature availability through switches, percentage-based samples, and user-targeted flags.

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

How Django in Action covers it

How deep it goes
Explains three controls, installation, Django configuration, migrations, administration, and basic evaluation calls without detailing flag internals.
Examples
Uses switches, percentage samples, targeted flags, beta testing, and guarded feature blocks as practical examples.
What it assumes
Assumes a Django project and basic application configuration; teaches the package setup and three control types directly.
What you can do after
Operate Django Waffle to configure controls and conditionally expose application features to selected visitors.
How it connects
Connects feature flags with Django models, middleware, Django Admin, database migrations, and conditional code.

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Django in Action. The section links point to the parts of the book it draws on.