Home > Software engineering >  how to configure the schema name to PostgreSQL Database in Flask-session
how to configure the schema name to PostgreSQL Database in Flask-session

Time:11-24

I succeeded in creating a sessions table with flask_session, but now I need to set the schema name in the PostgreSQL database. How do I set it up?

def create_app():
    app = Flask(__name__)

    cors = CORS(app, resources={r"/*": {"origins": "http://localhost:8080/"}})
    app.config['SESSION_TYPE'] = 'sqlalchemy'
    app.config['SQLALCHEMY_DATABASE_URI'] = 'postgresql://postgres:password@localhost:5432/database'
    app.config['SQLALCHEMY_TRACK_MODIFICATIONS'] = False
    app.config["SESSION_SQLALCHEMY_TABLE"] = "sessions" #default sessions
    app.config["SESSION_COOKIE_SECURE"] = True
    app.config["PERMANENT_SESSION_LIFETIME"] = timedelta(seconds=50)
    session = Session(app)
    session.app.session_interface.db.create_all()


    return app

CodePudding user response:

Resolved, by adding the options parameter to the url.

postgresql://postgres:password@localhost:5432/database?options=-c search_path=schema_name

  • Related