title: How to return error message in decorator in Django?
body: <p>I wrote my own decorator, which checks if the currently logged in user is a teacher. If not, the decorator redirects the user to the login page, but for the user it is a bit confusing, so I want to pass a message why the user was redirected to the login page, but I have no idea how to do it.</p>
  
  <pre class="lang-py prettyprint-override"><code># here is my decorator:
  def teacher_required(function=None, redirect_field_name=REDIRECT_FIELD_NAME, login_url='login'):
      '''
      Decorator for views that checks that the logged in user is a teacher,
      redirects to the log-in page if necessary.
      '''
      actual_decorator = user_passes_test(
          lambda u: u.is_active and u.is_teacher,
          login_url=login_url,
          redirect_field_name=redirect_field_name
      )
      if function:
          return actual_decorator(function)
      return actual_decorator
  </code></pre>