Enforcing login on all Flask blueprint routes

Posted on Wed 26 February 2020 in posts

I found this tip on the Flask subreddit, such a simple solution to make sure you don't forget to add a @login_rquired to a route. You can enforce user login with Flask-Login by using the @before_request decorator.

@bp.before_request
@login_required
def handle_route_permissions():
    # just used to enforce login required on all views
    pass