Flask Version:
>>> flask.__version__
'0.12.2'
I don't want to update the expiration time for a certain URL.
Currently, I use the following method for setting session expiration time:
session.permanent = true
app.permanent_session_lifetime = timedelta(minutes=int(10))
I have a status page which auto-refreshes every minute using an ajax method to get only the data.
I don't want to reset the session expiration time in this case.
Is there any way to do so?
Edit:
My Code so far:
from datetime import timedelta
from flask import Flask
from flask import session
APP = Flask(__name__, static_url_path='', static_folder='templates')
def create_user_session(user_accountid, auth_token):
session['token'] = auth_token
session['user_accountid'] = user_accountid
def update_session():
session.permanent = True
APP.permanent_session_lifetime = timedelta(minutes=10)
session.modified = True
@APP.route('/batch_status', methods=['GET'])
def view_status():
create_user_session(1, "****")
update_session()
return "Session Change"
@APP.route('/batch_status_json', methods=['GET'])
def retrieve_status():
return "Session No Change"
if __name__ == '__main__':
APP.secret_key = "My Precious Key"
APP.run(host='0.0.0.0', debug=True, port=8000)
I don't want to change the session expiration time on batch_status_json
call but it automatically changes when called.
Edit2:
monitor_controller.py:
from datetime import timedelta
from flask import Flask
from flask import session
from status import RETRIEVE_STATUS
APP = Flask(__name__, static_url_path='', static_folder='templates')
APP.register_blueprint(RETRIEVE_STATUS)
def create_user_session(user_accountid, auth_token):
session['token'] = auth_token
session['user_accountid'] = user_accountid
def update_session():
session.permanent = True
APP.permanent_session_lifetime = timedelta(minutes=10)
session.modified = True
@APP.route('/batch_status', methods=['GET'])
def view_status():
create_user_session(1, "****")
update_session()
return "Session Change"
if __name__ == '__main__':
APP.secret_key = "My Precious Key"
APP.run(host='0.0.0.0', debug=True, port=8000)
status.py:
from flask import Blueprint
RETRIEVE_STATUS = Blueprint('retrieve_status', __name__)
@RETRIEVE_STATUS.route('/batch_status_json', methods=['GET'])
def retrieve_status():
return "Session No Change"
The cookies are set if the session is marked modified OR if the SESSION_REFRESH_EACH_REQUEST
option is set. By default the option is True.
In your Flask config try setting
SESSION_REFRESH_EACH_REQUEST = False
From the documentation:
SESSION_REFRESH_EACH_REQUEST
Control whether the cookie is sent with every response when session.permanent is true. Sending the cookie every time (the default) can more reliably keep the session from expiring, but uses more bandwidth. Non-permanent sessions are not affected.
Default: True
Collected from the Internet
Please contact [email protected] to delete if infringement.
Comments