title: Multiple decorators for a view in Django: Execution order
body: <p>I am trying to decorate a Django view by two decorators, one for checking login, and one for checking is_active.</p>
  
  <p>The first one is the built-in <code>@login_required</code>, and the second one is the following:</p>
  
  <pre><code>def active_required(function):
      dec = user_passes_test(lambda u: u.is_active, '/notallowed', '')
      return dec(function)
  </code></pre>
  
  <p>Now, the decorators in Python work inside out, however the following does not work:</p>
  
  <pre><code>@active_required
  @login_required
  def foo(request):
      ...
  </code></pre>
  
  <p>I want to first check if the user is logged in, and redirect to login page if not, and if he or she is logged in, I want to check whether he or she is active, and if not, perform redirect to <code>'/notallowed'</code>. </p>
  
  <p>What happens is that if the login_required fails, the user is not redirected to the login page, but <code>@active_required</code> is executed, and since the user is null in that case, @active_required decorator fails and the user is redirected to <code>/notallowed</code>.</p>
  
  <p>Changing the order seems to work,</p>
  
  <pre><code>@login_required
  @active_required
  def foo(request):
      ...
  </code></pre>
  
  <p>but I suspect there is something wrong with this approach too.</p>
  
  <p>What is the proper way to combine two decorators, and why does the execution order differ from simple Python decorators?</p>