How to manage beta testers in Django
Published: 02 Sep 2015
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.
Create the beta testers group
Open a shell with ./manage.py shell and create a user group:
from django.contrib.auth.models import Group group = Group() group.name = 'Beta testers' group.save() print(group.id)
Create a flag
Reusing the previous shell, create a feature flag:
from waffle.models import Flag flag = Flag() flag.name = 'new_feature' flag.group = 72 # replace 72 by the id from the previous step flag.save()
Use a flag in templates
{% flag flag_name %}
Flag is active!
{% else %}
Flag is inactive!
{% endflag %}
Use a flag in views
if waffle.flag_is_active(request, 'new_feature'):
# Behavior if flag is active.
else:
# Behavior if flag is inactive.