I'm building a multi-tenant Django app, where I need to check for a certain condition before processing each view, similar to the login_required decorator which checks if user is authenticated or not.
And if the condition is not true, stop processing the view and send the user to the login page.
How can I implement this for each view in my app
My condition -
def index_view(request):
domain1 = Domain.objects.get(tenant=request.user.client_set.first())
domain2 = request.META["HTTP_HOST"].split(":")[0]
# Condition
if str(domain1) != domain2:
return redirect("accounts:login")
return render(request, "dashboard/index.html")