我在登陆的时候 自己写的login_user 里 将 user 对象保存在 g中,g.user = user 然后刷新了页面,但是当页面刷新后,g中就没有user了,请问怎么保存user在g中呢?
我在登陆的时候 自己写的login_user 里 将 user 对象保存在 g中,g.user = user 然后刷新了页面,但是当页面刷新后,g中就没有user了,请问怎么保存user在g中呢?
4 回答4.4k 阅读✓ 已解决
4 回答3.8k 阅读✓ 已解决
1 回答3k 阅读✓ 已解决
3 回答2.1k 阅读✓ 已解决
1 回答4.5k 阅读✓ 已解决
1 回答3.8k 阅读✓ 已解决
1 回答2.8k 阅读✓ 已解决
To share data that is valid for one request only from one function to another, a global variable is not good enough because it would break in threaded environments. Flask provides you with a special object that ensures it is only valid for the active request and that will return different values for each request. In a nutshell: it does the right thing, like it does for request and session.
你应该用session:http://flask.pocoo.org/docs/0.10/quickstart/#sessions