【问题标题】:Unexpected working of new attribute of Session class in FlaskFlask 中 Session 类的新属性的意外工作
【发布时间】:2017-12-21 23:40:10
【问题描述】:

根据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'

【问题讨论】:

  • 它看起来像错误。 JFYI

标签: python session flask


【解决方案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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2015-12-18
    • 1970-01-01
    • 2018-05-20
    • 2018-11-29
    • 1970-01-01
    • 1970-01-01
    • 2021-02-08
    • 1970-01-01
    相关资源
    最近更新 更多