title: When session expired ,do any actions will redirect login page by Django
body: <p>I use <code>Django 1.9</code> and <code>Python 3.5</code>. I set session expiry time 1800 seconds.  When the session expired, I only click the url or reload the page, the page redirect the login page.  I want to do any actions on the page redirect login page.  What should I do?</p>
  
  <p>my settings:</p>
  
  <blockquote>
    <p>MIDDLEWARE_CLASSES = 
    ( 'django.contrib.sessions.middleware.SessionMiddleware', 'django.middleware.common.CommonMiddleware', 'django.middleware.csrf.CsrfViewMiddleware', 'django.contrib.auth.middleware.AuthenticationMiddleware', 'django.contrib.auth.middleware.SessionAuthenticationMiddleware', 'django.contrib.messages.middleware.MessageMiddleware', 'django.middleware.clickjacking.XFrameOptionsMiddleware', 'django.middleware.security.SecurityMiddleware',
    'zeus.middleware.SessionMiddleware', )</p>
  </blockquote>
  
  <hr>
  
  <p>my middleware:</p>
  
  <pre><code>  # -*- coding: utf-8 -*-  
       try:
          from django.utils.deprecation import MiddlewareMixin   
       except ImportError:
          MiddlewareMixin = object
  
      class SessionMiddleware(MiddlewareMixin):
          def process_request(self,request):
             pass
          def process_response(self,request,response):
              if hasattr(request,'user'):
                  if request.user.is_authenticated():
                      request.session.set_expiry(1800)
              return  response
  </code></pre>