A little javascript and middleware work together to ensure that the user was active during the past X minutes in any tab he has open. Otherwise, display a warning leaving a couple of minutes to show any kind of activity like moving the mouse. Otherwise, logout the user.
I think settings.MIDDLEWARE_CLASSES here is now deprecated?
PS: Also the "Edit on Github" link in top right corner of the webpage is broken.