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 requset- set
permanent_session_lifetimeto 1 microsecond
code:
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:
- How do I make
session.newto beTrue? - If I start a new session, will
session.newbeTrue? - It seems
session.clear()can only clear the content of session, am I right? - How do I start a new session in Flask?