This example with decorators:
@app.route('/')
@login_required
def index():
pass
is equivalent to this example without decorators:
def index():
pass
app.add_url_rule('/', 'index', login_required(index))
Question
I have an app, which is quite big, so it's divided into modules and use blueprints
, add_url_rule
for routing to various modules. Everything works fine and as intented.
The problem is, I need to use the Flask-Login (https://flask-login.readthedocs.org/en/latest/#api-documentation), from the documentaion. I could only find how to protect views using decorators
, for which the app should have routes set using the app.route('/home')
. But like I already mentioned, I'm using blueprints
and add_url_rule
.
EDIT: The answer @Mark Hildreth edited into this question, is the required solution. Thank you.
Solution
This example with decorators:
@app.route('/')
@login_required
def index():
pass
is equivalent to this example without decorators:
def index():
pass
app.add_url_rule('/', 'index', login_required(index))