Answer the question
In order to leave comments, you need to log in
Which is better to use: decorator or before_request?
There are options:
1) Use a decorator for private parts of the site where authorization is required:
@login_required
@app.route('/members/' )
@app.before_request
def before_request():
user_id = session.get('user_id', None)
if not user_id and request.path.startswith('/members/'):
return redirect(url_for('login'))
Answer the question
In order to leave comments, you need to log in
There is no correct option.
See what you need specifically in your case.
You can compare them for response speed, memory consumption and more, more.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question