When I make multiple requests, data doesn't get persisted.
I tried just to set session value in regular way (like in flask docs) but it doesn't work neither, session['array']
gets declared every time I make a new request.
secret_key
is in the place.
Here is my route:
from flask import session
...
@app.route('/add', methods=['POST'])
@ath.login_required
def add():
"""
adds an integer(s) to Array used for calculation.
Parameters:
integer(s): Integer or list of integers
"""
param = request.json.get('integer')
if not param:
abort(make_response(jsonify("Param is not valid"), 400))
if 'array' not in session:
# each time I make a request, program enters this block
session['array'] = []
# I want to append more stuff into a session object
# these 3 next lines are supposed to enable that
# found it here: https://stackoverflow.com/questions/34630709
array = session['array']
array.append(param)
session['array'] = param
return jsonify({'success': session['array']}), 200
Making a request with curl: curl -u token -i -X POST -H "Content-Type: application/json" -d '{"integer": 2}' http://127.0.0.1:6767/add
What I am doing wrong?