Managing beta testers in Django

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:

  1. add waffle to INSTALLED_APPS.
  2. add waffle.middleware.WaffleMiddleware to MIDDLEWARE_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:

  1. from django.contrib.auth.models import Group
  2. group = Group(name='beta-testers')
  3. 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.