Tracy of AI
8/10/2018 - 1:51 PM

Session Handling

Code for handing sessions in Flask

#Session Handling
import session
app.config['SECRET_KEY'] = 'any random string' #must be set to use sessions
#set session
@app.route('/login_success')
def login_success():
 session['key_name'] = 'key_value' #stores a secure cookie in browser
 return redirect(url_for('index'))
#read session
@app.route('/')
def index():
 if 'key_name' in session: #session exists and has key
 session_var = session['key_v