2017-12-19 4 views
2

Gemäß der Flask Dokumentation gibt new Attribut True zurück, wenn die Sitzung neu ist. sonst False, aber in meinem Fall gibt es immer False egal was. Hier ist der Code:Unerwartete Funktion des neuen Attributs der Sitzungsklasse in Flask

@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' 
+0

Es sieht aus wie Bug. [JFYI] (https://github.com/pallets/flask/issues/2564) –

Antwort

1

Vom 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 

Die Standardsitzung versucht nicht, zu verfolgen, ob eine Sitzung neu.

Siehe this issue on GitHub

Verwandte Themen