Flask中Session类的新属性意外工作

问题描述 投票:2回答:1

根据Flask文档,如果会话是新的,new属性返回True。否则False,但在我的情况下,它总是返回False无论如何。这是代码:

@app.route('/set-session/')
def testing_session():
    session['user_id'] = 'jon'
    print(session.new)    # always returns True . Why ?
    print(session.modified)
    return 'playing with session'
python session flask
1个回答
1
投票

来自code

#: some session backends can tell you if a session is new, but that is
#: not necessarily guaranteed.  Use with caution.  The default mixin
#: implementation just hardcodes ``False`` in.
new = False

默认会话不会尝试跟踪会话是否为新会话。

this issue on GitHub

© www.soinside.com 2019 - 2024. All rights reserved.