在烧瓶中使用会话

Using sessions in flask

我想在会话中添加项目并在烧瓶中删除会话。谁能帮忙写代码?

from flask import Flask, session

app = Flask(__name__)

@app.route('/home')
def hello world():
    return "Hello world"

您可以从 flask 导入会话并使用它

from flask import Flask, session

app = Flask(__name__)

@app.route('/use_session')
def use_session():
    if 'item' not in session:
        session['items'] = {'item':'item2'}

return session.get('items')

@app.route('/delete_session'):
def delete_session():
    session.pop('item', None)
    return "removed item from session"