Search code examples
pythondjangoab-testing

Build a simple django A/B Testing framework


I am not a expert django developer. I am building a site to gather user information and also run experiments. I want to build an A/B testing module to simply do following:

  1. Randomly assign users to control and test group
  2. Depend on the group that user is in allow user to have access to features.

I saw some heavyweight A/B testing modules they seems very complicated for my application and I realize adding something like that without understanding many nuts and bolts in django would cause me more trouble.

My question is how should I start building this? Can someone point me towards similar sample code where I can begin with and then built on top of that.


Solution

  • The simplest (but definitely not the best) way would be to do something like this:

    def some_view(request):
        test_pool = request.user.id % 2  # all users will be in test_pool 0 or 1
        if test_pool == 0:
            # allow feature
        else:
            # don't allow feature