$ show cfpb/django-flags
Django-Flags is a reusable Django application that provides a feature flag system with configurable conditions. It allows developers to toggle functionality in code, templates, and URL routing based on conditions such as boolean, user, date, request parameters, path matches, and custom conditions. Flags can be defined in Django settings or stored in the database and managed via the Django admin. The library includes decorators for views, template tags for Django and Jinja2, URL pattern helpers for conditional routing, and debugging support via Django Debug Toolbar panels. It is actively maintained, supports Django 4.2 through 6.0, and follows modern Python packaging and linting practices.
The LLM identified 2 files worth highlighting for reuse:
A generic plugin registry for condition functions. Provides a register() decorator/function to add named callables, get_condition() and get_conditions() lookups, and handles duplicate registrations with a DuplicateCondition exception. It also attaches an optional validator to the callable. This module is self-contained with no Django dependencies and can be extracted for any project needing a simple plugin or condition registry.
Implements conditional URL routing based on feature flag state. Provides flagged_path, flagged_re_path, and context managers flagged_paths/flagged_re_paths that wrap Django's URL pattern functions. The FlaggedURLResolver handles included URL patterns with fallback views, ensuring that when a flag is enabled the primary view is used and when disabled the fallback (or 404) is served. Demonstrates deep integration with Django's URL resolver and provides a reusable pattern for feature-flagging entire URL configurations.