Recall & Review
beginner
What is the purpose of the
login_required decorator in Flask?The
login_required decorator ensures that a user must be logged in to access a specific route or view. If the user is not logged in, they are redirected to the login page.Click to reveal answer
beginner
How do you apply the
login_required decorator to a Flask route?You place
@login_required above the route function definition. For example:<br>@app.route('/dashboard')<br>@login_required<br>def dashboard():<br> return 'Welcome!'Click to reveal answer
beginner
Which Flask extension provides the
login_required decorator?The
Flask-Login extension provides the login_required decorator to manage user sessions and protect routes.Click to reveal answer
beginner
What happens if a user who is not logged in tries to access a route protected by
login_required?They are redirected to the login page, usually specified by the
login_view setting in Flask-Login. This prevents unauthorized access.Click to reveal answer
intermediate
Can you customize where users are redirected if they are not logged in when using
login_required?Yes, you can set the login page route by configuring
login_manager.login_view in your Flask app. For example:<br>login_manager.login_view = 'login'
Click to reveal answer
What does the
login_required decorator do in Flask?✗ Incorrect
The
login_required decorator restricts access to routes for users who are not logged in.Which Flask extension must you install to use
login_required?✗ Incorrect
login_required is provided by the Flask-Login extension.If a user is not logged in and tries to access a protected route, what happens?
✗ Incorrect
Users not logged in are redirected to the login page when accessing routes with
login_required.How do you specify the login page URL for
login_required redirection?✗ Incorrect
You configure
login_manager.login_view to set the login page URL.Where do you place the
@login_required decorator in your Flask code?✗ Incorrect
Decorators like
@login_required go above the route function definition.Explain how the
login_required decorator works in Flask and why it is useful.Think about what happens when a user tries to visit a page without logging in.
You got /4 concepts.
Describe the steps to protect a Flask route using
login_required.Consider setup and usage in code.
You got /4 concepts.