Skip to content

Instantly share code, notes, and snippets.

@dryan
Created December 18, 2009 20:01
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
Star You must be signed in to star a gist
Save dryan/259723 to your computer and use it in GitHub Desktop.
Django middleware for extending session expiration on access
class InactivityLogout(object):
def process_request( self, request ):
from datetime import datetime, timedelta
from django.conf import settings
COOKIE_AGE = getattr(settings, 'SESSION_COOKIE_AGE', 7200)
if datetime.now() – request.session.get_expiry_date() < timedelta(seconds = COOKIE_AGE):
request.session.set_expiry(datetime.now() + timedelta(seconds = COOKIE_AGE))
return None # pass through
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment