1.

How to use a session in Flask?

Answer»

Flask-SESSION is a Flask extension that adds server-side session FUNCTIONALITY to your application. The Session is the period of time between when a CLIENT logs in and logs off of a server. The data that must be saved in the session is saved on the server in a temporary directory. We can utilize session objects in Flask whenever we need to SAVE a large quantity of data between queries. The session object can be used to set and obtain data, as demonstrated below -

from flask import Flask, session   app = Flask(__name__)   @app.route('/use_session') def use_session()     if 'song' not in session:         session['songs'] = {'title': Perfect, 'singer': 'Ed Sheeran'}       RETURN session.get('songs')   @app.route('/delete_session') def delete_session()     session.pop('song', None)     return "removed song from session"


Discussion

No Comment Found