How to view all Feature Flags in views.py

136 Views Asked by At

I have added feature flags in my django using package django-waffle. I defined a switch in django admin panel. The default Switch model provides all the necessary functionality.To list all the switches using manage.py, we use this command:

./manage.py waffle_switch -l

How to list all the switches in views.py?

1

There are 1 best solutions below

0
On

Something like that should work for switches

from django.http import HttpResponse
from waffle import get_waffle_switch_model


def index(request):
    switches = get_waffle_switch_model().get_all()
    switch_values = [(f.name, f.is_active(request)) for f in switches]

    return HttpResponse(switch_values)

and for feature flags pretty similar:

from django.http import HttpResponse
from waffle import get_waffle_flag_model

def index(request):
    flags = get_waffle_flag_model().get_all()
    flag_values = [(f.name, f.is_active(request)) for f in flags]

    return HttpResponse(flag_values)