Welcome to Software Development on Codidact!
Will you help us build our independent community of developers helping developers? We're small and trying to grow. We welcome questions about all aspects of software development, from design to code to QA and more. Got questions? Got answers? Got code you'd like someone to review? Please join us.
Post History
class ExtendUserSession(MiddlewareMixin): """ Extend authenticated user's sessions so they don't have to log back in following 15 minutes (set by Django's default `SESSION_COOKIE_A...
#1: Initial revision
Need help in migrating a Python2 custom middleware to current Python3 version
``` class ExtendUserSession(MiddlewareMixin): """ Extend authenticated user's sessions so they don't have to log back in following 15 minutes (set by Django's default `SESSION_COOKIE_AGE` setting). """ def process_request(self, request, get_response): current_user = request.user # Only extend the session for auth'd users if request.user.is_authenticated: reason = CsrfViewMiddleware('get_response').process_view(request, None, (), {}) if reason: # process_view returns HTTPException pass else: # process_view returns None - No error on HTTP request from CSRF middleware verification request.session.set_expiry(86400) ``` In this method, the admin can log in inside the website but after any post request, the session gets expires and returns to the login page