I want to add items in session and delete sessions in flask. Can anyone help with the code?
from flask import Flask, session
app = Flask(__name__)
@app.route('/home')
def hello world():
return "Hello world"
CodePudding user response:
You can import session from flask and use it
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"