Sanic: pass data from app to blueprint

Created on 24 Aug 2017  路  2Comments  路  Source: sanic-org/sanic

So im creating an app using several blueprints to keep my endpoints ordered, in my sanic app file i've a before_server_start listener creating the DB connection to mongo using motor.

I want to have access to this connection var from each blueprint because i will initialize a different model in every blueprint, i didnt find any of this in the docs, it is possible? there is any better solution?

question

Most helpful comment

use app.db = ... then in the blueprint use request.app.db to access it.

All 2 comments

use app.db = ... then in the blueprint use request.app.db to access it.

It worked, thanks, clossing this.

Was this page helpful?
0 / 5 - 0 ratings