Reputation: 474
Setting a variable in request.session
with
request.session['display_name'] = 'foo'
and then displaying throughout my app with
request.session.display_name
Which works just fine throughout the app. If left alone for about 20 minutes however, I can no longer call it. I get:
AttributeError: 'CookieSession' object has no attribute 'display_name'
Reading up on how pyramid sessions are supposed to work, it should still exist for duration of the browser scope.
Any ideas why it gets removed after a while?
Upvotes: 3
Views: 516
Reputation: 15045
See the definition for timeout:
A number of seconds of inactivity before a session times out. If None then the cookie never expires. This lifetime only applies to the value within the cookie. Meaning that if the cookie expires due to a lower max_age, then this setting has no effect. Default: 1200.
Assuming you don't set max_age
, or if you set max_age
to be 1200 or greater, then the default setting of timeout
(1200 seconds) will expire the cookie at that elapsed duration.
1200 seconds / 60 seconds per minute = 20 minutes
...which is consistent with your experience.
Try setting timeout
to your desired duration in seconds, or to None
to prevent the expiration of the cookie while the browser is open.
Upvotes: 5