0
0
Flaskframework~10 mins

Logout implementation in Flask - Interactive Code Practice

Choose your learning style9 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete the code to import the function needed to clear the user session in Flask.

Flask
from flask import [1]
Drag options to blanks, or click blank then click option'
Arequest
Brender_template
Csession
Dredirect
Attempts:
3 left
💡 Hint
Common Mistakes
Importing render_template instead of session.
Using request instead of session for logout.
2fill in blank
medium

Complete the code to remove all data from the user session during logout.

Flask
def logout():
    [1].clear()
    return redirect('/')
Drag options to blanks, or click blank then click option'
Arequest
Bapp
Cflask
Dsession
Attempts:
3 left
💡 Hint
Common Mistakes
Calling clear() on request or app objects.
Forgetting to clear the session before redirect.
3fill in blank
hard

Fix the error in the logout route decorator to correctly define the logout URL.

Flask
@app.route('[1]')
def logout():
    session.clear()
    return redirect('/')
Drag options to blanks, or click blank then click option'
A/logout
B/login
C/home
D/dashboard
Attempts:
3 left
💡 Hint
Common Mistakes
Using /login or other unrelated routes for logout.
Missing the leading slash in the route.
4fill in blank
hard

Fill both blanks to import redirect and define the logout route correctly.

Flask
from flask import [1], session

@app.route('[2]')
def logout():
    session.clear()
    return redirect('/')
Drag options to blanks, or click blank then click option'
Aredirect
Brequest
C/logout
D/login
Attempts:
3 left
💡 Hint
Common Mistakes
Importing request instead of redirect.
Using /login as the logout route.
5fill in blank
hard

Fill all three blanks to complete a logout function that clears the session, flashes a message, and redirects to login.

Flask
from flask import [1], session, redirect, url_for
from flask import flash

@app.route('/logout')
def logout():
    session.[2]()
    flash('You have been logged out successfully.', '[3]')
    return redirect(url_for('login'))
Drag options to blanks, or click blank then click option'
Aflash
Bclear
Cinfo
Drequest
Attempts:
3 left
💡 Hint
Common Mistakes
Not importing flash and trying to call it.
Using session.pop() instead of clear() for full logout.
Using wrong flash category like 'error'.