Eva611
Eva611

Reputation: 6194

Django logout and redirect after inactivity

By setting SESSION_COOKIE_AGE and turning SESSION_SAVE_EVERY_REQUEST, it will log people out after a certain time of inactivity. But is there anyway to redirect after say 5 mins of inactivity?

Upvotes: 1

Views: 1488

Answers (2)

Martin Larente
Martin Larente

Reputation: 520

If you want to redirect without any action from the user, you have to do it in javascript:

setTimeout(function() { window.location.href = 'http://someURL'; }, 5 * 60 * 1000);

Upvotes: 2

kcbanner
kcbanner

Reputation: 4078

You can use setTimeout() to trigger an ajax request, and if it responds with a redirect (you have been logged out), then refresh the page. This method is superior to simply refreshing the page every 5 minutes, as that may be a bad user experience.

Upvotes: 3

Related Questions