How to apply a decorator to all drawings in a bulb

I have a project and some URL functions,

admin_bp = Blueprint('admin', __name__) @admin_bp.route('/dashboard', methods=['GET', ]) @flask_login.login_required def dashboard(): context = {} page = 'admin/dashboard.html' return render_template(page, **context) @admin_bp.route('/deny', methods=['GET', ]) @flask_login.login_required def deny(): return 'hey bro you dont belong here' 

I do not want to copy the @flask_login.login_required decorator insert for all url functions according to this plan. Is there a better way that I can apply a decorator to all drawings?

+5
source share
1 answer

How about user verification:

 from flask.ext.login import current_user @admin_bp.before_request def check_user(): if not current_user.is_authenticated(): abort(401) # your other functions without `@flask_login.login_required` 
+1
source

All Articles