Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Using sessions in flask

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"

>Solution :

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

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"
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading