Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Before_request for multiple Blueprints

Tags:

python

flask

Here's my situation:

Let's say I have 2 Blueprints before_request method:

mod = Blueprint('posts', __name__, url_prefix='/posts')

@mod.before_request
def before_request():
  #some code that uses SQLAlchemy here 
  pass

Now I don't want to duplicate the logic in this method in the second blueprint.

How can I do this?

PS: I'm new to Python so I might be missing something obvious. Thanks.

like image 290
sirrocco Avatar asked Mar 16 '13 06:03

sirrocco


1 Answers

use blueprint.before_app_request which applies to views app-wide, not only views in the same blueprint

like image 106
thkang Avatar answered Sep 23 '22 16:09

thkang