Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
# -*- coding: utf-8 -*-
# $ pip install beaker flask redis git+git://
from flask import Flask, session
from flask.sessions import SessionInterface
from beaker.middleware import SessionMiddleware
session_opts = {
'session.type': 'redis',
'session.url': '',
class BeakerSessionInterface(SessionInterface):
def open_session(self, app, request):
return request.environ['beaker.session']
def save_session(self, app, session, response):
app = Flask(__name__)
def index():
if not session.has_key('value'):
session['value'] = 'Save in session'
return "Session value set."
return session['value']
if __name__ == '__main__':
app.wsgi_app = SessionMiddleware(app.wsgi_app, session_opts)
app.session_interface = BeakerSessionInterface()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment