I am attempting to implement Flask-Session in my python application. I read in the docs that its recommended to use another interface like the SqlAlchemySessionInterface
instead of the default NullSessionInterface
which is used when nothing is provided to the SESSION_TYPE
configuration key.
From the flask_session/init.py file under class Session it reads
By default Flask-Session will use :class:
NullSessionInterface
, you really should configurate your app to use a different SessionInterface.
After setting the SESSION_TYPE
configuration key to "sqlalchemy"
I get an error
sqlalchemy.exc.ProgrammingError: (psycopg2.ProgrammingError) relation "sessions" does not exist
This indicates that Flask-Session is looking to use a table with the name "sessions" in my database model but I cannot find anywhere in the Flask-Session documentation where it points out that a table should be created and what fields it should have.
Can anyone suggest a solution to this please?
After studying the Flask-Session/init.py code I found that class SqlAlchemySessionInterface under its
__init__
contains a Flask-SQLAlchemy modelclass Session(self.db.Model)
. To cause this table model to be created, in the file where I create my models I importedSqlAlchemySessionInterface
fromflask_sessionstore
and put the lineSqlAlchemySessionInterface(myApp, sqlAlchemyDbObject, "table_name", "prefix_")
and then ran db.create_all().I'am definitely using Django for my next project. Documentation for many Flask Extensions aren't great at all.
EDIT
Changed (imported SqlAlchemySessionInterface from flask_session) to (imported SqlAlchemySessionInterface from flask_sessionstore)