Sometimes you want to show a user a different feature. Or you want to test it in the production environment without affecting the other users. Or you have a group of beta testers for which you rely on early feedback to improve your app. Below is how to do this using django-waffle.
Install django-waffle
Install the waffle package by running:
pip install django-waffle
Open your app's settings.py and:
- add
waffletoINSTALLED_APPS. - add
waffle.middleware.WaffleMiddlewaretoMIDDLEWARE_CLASSES.
And you're ready to go.
Create the beta testers group
Note: If you want to reuse an already existing group, just note its id for the next step.
Open a shell with:
./manage.py shell
and create a user group:
from django.contrib.auth.models import Groupgroup = Group(name='beta-testers')group.save()
Configure Waffle
Go to the Django admin panel, look for the 'Waffle' section, and create a new 'Flag'. Set the 'Groups' field to select your 'beta-testers' group. You can now use this flag in your templates or views to toggle features specifically for this group.