I saw the description of session.new
in the Documents
It said:
session.new
is True
if the session is new, False otherwise.
So I tried two things in the following code:
session.clear()
before requsetpermanent_session_lifetime
to 1 microsecondcode:
from flask import Flask, render_template, session
from datetime import datetime, timedelta
app = Flask(__name__)
app.config['SECRET_KEY'] = 'hard to guess string'
app.config['permanent_session_lifetime']=timedelta(microseconds=1)
@app.before_request
def clear_session():
session.permanent=True
session.clear()
@app.route('/session', methods=['GET','POST'])
def get_session():
print(session)
print(session.new)
return render_template('session.html')
the results are:
<SecureCookieSession {}>
False
Now I have a few questions:
session.new
to be True
?session.new
be True
?session.clear()
can only clear the content of session, am I right?If you look at the source code of session.new, you will notice that it contains,
new = False
So, by default the value of new is always false. The only you can try is maybe by changing your app's secret key and launching the server fresh where all previous sessions are revoked obviously.