I recently did authentication using class and mixin views. See LoginRequiredMixin in django-braces for an example.
This means that all of your views (which you want to protect) should include a common mix, but this is the purest way I know this.
Usage (from docs ) is as follows:
from django.views.generic import TemplateView from braces.views import LoginRequiredMixin class SomeSecretView(LoginRequiredMixin, TemplateView): template_name = "path/to/template.html" def get(self, request): return self.render_to_response({})
You probably want to define your own mixin, which might look like this (not verified):
class AcceptedTOSRequiredMixin(object): def dispatch(self, request, *args, **kwargs): profile = request.user.get_profile() if not profile or profile.accepted_tos_at is None: return HttpResponseForbidden()
Other ways to do this include decorating them at the URL level, but this is ugly in my opinion (I would be happy to dig up an example of what it looks like if that helps).
source share