based on ideas from django_brookie