How to manage beta testers in Django

2 Sep 2015 by rolo

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.

Create the beta testers group

Open a shell with ./manage.py shell and create a user group:

  1. from django.contrib.auth.models import Group
  2. group = Group.objects.create(name='Beta testers')

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.