Class-based views

from flags.views import (
    FlaggedViewMixin,
    FlaggedTemplateView,
)

API

FlaggedViewMixin

Adds flag-checking to HTTP method dispatching in class-based views.

Attributes

`flag_name`
The feature flag this view depends on.
`state`
Either `True` or `False`, the state the feature flag should be in. By default, `state` is `True`, requiring the flag to evaluate to `True`.
`fallback`
A view to fallback on if the flag does not match the required `state`. Defaults to `None`, causing the view to raise a `404` if the flag does not match the required `state`.

Note

When a fallback view is given it must take the same arguments as the flagged view.

For example, in views.py:

from django.views.generic import View
from flags.views import FlaggedViewMixin

class MyFlaggedView(FlaggedViewMixin, View):
    def get(self, request, *args, **kwargs):
        return HttpResponse('ok')

And in urls.py:

from django.urls import path
from flags.urls import flagged_path

urlpatterns = [
    path('my-url/', MyFlaggedView.as_view(flag_name='MY_FLAG'))
]

FlaggedTemplateView

A combination of TemplateView and FlaggedViewMixin.

For example, in views.py:

from flags.views import FlaggedTemplateView

class MyFlaggedView(FlaggedTemplateView):
    template_name = "mytemplate.html"
    flag_name = 'MY_FLAG'

Or to serve a template directly in urls.py:

from django.urls import path
from flags.views import FlaggedTemplateView

urlpatterns = [
    path(
        'my_url/', 
        FlaggedTemplateView.as_view(
            template_name='mytemplate.html', 
            flag_name='MY_FLAG'
        )
    ),
]