I am trying to implement Django basic authentication for all of the views in my views.py file. Although I can add the authentication code snippet in every view, but it will not be easy to apply this to upcoming views. Is there any way that every view in my views.py will automatically check for the authentication? views.py def mgmt_home(request): ############################################################## # This code is repetitive ############################################################## if request.user.is_anonymous: return redirect("/login") ############################################################## test_name = Test.objects.all()[0].test_name metadata = { "test_name": test_name, } return render(request, "mgmt_home.html", metadata) Is there any way where I can avoid this repetitive code in all of my views? Continue reading...