我一直在尝试清除会话,但它并未全局清除。
这是我的代码:
app = Flask(__name__)
app.secret_key = 'xxxxx'
@app.before_request
def make_session_permanent():
session.permanent = True
app.permanent_session_lifetime = timedelta(minutes=30)
@app.route('/')
def index():
session['game'] = 1
session['level'] = 1
return render_template('index.html')
@app.route('/level', methods=['POST', 'GET'])
def show_session():
x = (session.get('game'), session.get('level'))
return jsonify(x)
@app.route('/clear-session', methods=['POST', 'GET'])
def clear_session():
session.clear()
response = {'level': session.get('level')}
return jsonify(**response)
这是我用来发送AJAX请求的JavaScript代码段:
$.post('http://localhost:8000/level', function(data){console.log(data);}) // returns data
$.post('http://localhost:8000/clear-session', function(data){ console.log(data);}) // returns null as data is cleared
$.post('http://localhost:8000/level', function(data){console.log('session cleared'); console.log(data);}) //returns data again. Session not cleared properly
当我向clear-session发送请求时,如何克服此问题并永久清除会话?