简体   繁体   中英

How to set session's limit in flask?

Where can I increase the limit of what a session can store?

The project sometimes need to pass parameters from one page to another, so I store the parameters data in the session

I choose this method because I can only come up with two methods to let another page get the first page's data; either via the query string, or by session. However, I think the query string can't store too much data, so I choose the second method, is that any other way to achieve this?

Sometime the data's length can reach 25000 items (a little more than 20k), and the website won't pass this on.

I think because the session's limit is 20k, but I don't know where to set it.

I'm using Flask with Python 3.5.

The default Session implementation in Flask stores data in a browser-side cookie . It's a base64-encoded string with an (optionally compressed) JSON string, that is cryptographically signed to prevent tampering.

How large this cookie gets depends on the nature of your data, as compression can bring down the size considerably. The limits of what you can store in a cookie are relatively low and depend on the browser, but typically is 4kb. See http://browsercookielimits.iain.guru/ . Suffice it to say that you can't raise this limit.

If you need to store more data, you'll need to pick a different session implementation. Take a look at Flask-Session , which lets you tie a small identifier cookie to server-side stored data (in memcached, redis, the filesystem or a database). This will let you track much more data per browser session.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM