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
Install the waffle package by running:
pip install django-waffle
Open your app's
And you're ready to go.
Note: If you want to reuse an already existing group, just note its
id for the next step.
Open a shell with:
and create a user group (adjust the first line if you use another group Model other than the one from
from django.contrib.auth.models import Group
group = Group()
group.name = 'Beta testers'
id of the new group for the next step.
Note: you can also do this on the admin site.
Reusing the previous shell:
from waffle.models import Flag
flag = Flag()
flag.name = 'new_feature'
flag.group = 72 # replace 72 by the id from the previous step
Now that you have everything setup, it's time to use the flags in the code.
If you want to show a difference in a template, just add the
waffle_tags and use the
flag as you'd use an
If you want to switch between different codes in views, just
import waffle at the beggining of the file and then protect the differences with:
Don't overuse flags. Flags can be changed at runtime, so, for testing, you should test all the possible combinations. That adds a maintenance cost (in time and resources). As a rule of thumb I try to keep flags to a maximum of three at any point in time in a project.
Flags can also be used for phased roll-outs in Django. Check the documentation for that use case.
See the rest of the documentation at http://waffle.readthedocs.org/en/
The GOV.UK Design System is a toolkit and a set of guidelines for creating sites and services for Her Majesty's Government which are clear and consistent and accessible.
MangoPay presents itself as "Payments for Marketplaces", but it's far from being just a payment provider...
A lot of websites display notifications in one form or another these days. Facebook shows the new message notification, Gmail have the new mail notifications (with the support of browser notifications). I was asked today how hard it would be to implement a real-time notification system. The answer, as it...