liveBook · Manning

Feature flag

As explained in Django in Action

A feature flag is a conditional control that enables or disables application functionality according to configuration or runtime criteria.

A feature flag wraps new application code in a conditional so functionality can be enabled for some users while remaining hidden from others. This lets users beta-test production code and limits the risk of bad design decisions or misunderstood requirements. section 13.4

Django Waffle provides three levels of control: switches turn a feature on or off globally, samples expose it to a percentage of visitors, and flags select visitors using finer-grained criteria. section 13.4 section 13.6

A practical Waffle setup follows this path:

  • 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 `migrate`, because Waffle stores its state in database tables. section 13.4
  • Create controls through Django Admin or a management tool, then test them in application conditionals. section 13.4

A global rollout

Create a Waffle Switch named `new_profile`, then query it with `switch_is_active("new_profile")`. The returned Boolean decides whether the new profile code runs. For a percentage rollout, use a Sample and evaluate `sample_is_active()`; for user-specific targeting, use a Flag. section 13.4 section 13.6

How Django in Action covers it

How deep it goes
Explains conditional rollout, three Waffle control types, installation, configuration, migrations, and activation checks.
Examples
Uses Waffle switches for global rollout, samples for percentage rollout, and flags for role, account, language, or group targeting.
What it assumes
Assumes basic Django configuration while introducing feature rollout through concrete installation and database steps.
What you can do after
Apply feature rollouts via Django Waffle using switches, samples, and flags.
How it connects
Connects feature flags with conditional blocks, Django Waffle, Django Admin, middleware, database migrations, and unit tests.

Also explained in

Compare how 8 books explain feature flag →

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.