Freewind
Freewind

Reputation: 198318

How to set all cookies with a single max_age in pylons?

Normally, we set the cookie with a single max_age as following:

response.set_cookie('name1', 'value1', max_age=3600*24*365)
response.set_cookie('name2', 'value2', max_age=3600*24*365)
response.set_cookie('name3', 'value3', max_age=3600*24*365)

Note, we set the max_age again and again. How to set a default max_age to all cookies that does not have a max_age parameter? Is there any configuration for it?

Upvotes: 1

Views: 147

Answers (1)

estin
estin

Reputation: 3121

May be simple wrap set_cookie function:

def set_cookie(name, value, max_age=DEFAULT_MAX_AGE):
   response.set_cookie(name, value, max_age)

Upvotes: 1

Related Questions