Qty: logon session too early

When editing an entry, if there is a long wait, let me say a few minutes (drink coffee) and then return to press the save button (POST), I will be redirected to the main page to enter the system, and the data is lost.

The checkout check session seems to be expiring too quickly.

I did some research and came across this.

from flask import session, app session.permanent = True 

Is this the right way? But even when I try to do this, I get this exception:

  File "/Users/kave/workspace/F11A/src/application/__init__.py", line 14, in <module> session.permanent = True File "/Users/kave/workspace/F11A/src/lib/werkzeug/local.py", line 355, in <lambda> __setattr__ = lambda x, n, v: setattr(x._get_current_object(), n, v) File "/Users/kave/workspace/F11A/src/lib/werkzeug/local.py", line 297, in _get_current_object return self.__local() File "/Users/kave/workspace/F11A/src/lib/flask/globals.py", line 20, in _lookup_req_object raise RuntimeError('working outside of request context') RuntimeError: working outside of request context 
+6
source share
2 answers

Just in case, someone will have this question. I guess Homean has already received the answer.

Does not work

views.py

 from flask import session from datetime import timedelta session.permanent = True app.permanent_session_lifetime = timedelta(minutes=30) 

Will work

 from flask import session from datetime import timedelta @app.route('/home', methods=['GET', 'POST']) def show_work(): session.permanent = True app.permanent_session_lifetime = timedelta(minutes=30) form = MyForm(request.form) return render_template('home.html', form = form) 

session should be used inside the request.

+6
source

If you try to access a session object like this, it will not work.

As the error message flask.session , flask.session can only be used from a context that will not exist at this point. You should use it only within the route.

+2
source

Source: https://habr.com/ru/post/953343/


All Articles