0
0
Flaskframework~5 mins

Flash messages for user feedback in Flask - Cheat Sheet & Quick Revision

Choose your learning style9 modes available
Recall & Review
beginner
What is a flash message in Flask?
A flash message is a short message stored temporarily to show feedback to the user, like success or error notices, after a page reload or redirect.
Click to reveal answer
beginner
How do you add a flash message in Flask?
Use the flash() function with a message string inside a route function, for example: flash('Profile updated successfully!').
Click to reveal answer
beginner
How do you display flash messages in a Flask template?
Use a loop over get_flashed_messages() in your HTML template to show each message, often inside a styled alert box.
Click to reveal answer
beginner
Why are flash messages useful in web apps?
They provide clear, temporary feedback to users about actions like form submissions, helping users understand what happened without extra clicks.
Click to reveal answer
intermediate
What must you set in Flask to use flash messages securely?
You must set a secret key in your Flask app (e.g., app.secret_key = 'your_secret') to securely sign the session data used by flash messages.
Click to reveal answer
Which Flask function is used to create a flash message?
Aflash()
Bmessage()
Cnotify()
Dalert()
Where do flash messages get stored temporarily in Flask?
AIn the session
BIn the database
CIn a cookie
DIn a file
How do you retrieve flash messages in a Flask template?
AUsing fetch_messages()
BUsing get_flashed_messages()
CUsing show_flash()
DUsing get_messages()
What must you set in your Flask app to enable flash messages?
Aapp.config['FLASH'] = True
Bapp.debug = True
Capp.secret_key
Dapp.session_enabled = True
Flash messages are best used for:
ALogging errors on the server
BStoring user preferences permanently
CSending emails to users
DTemporary user feedback after actions
Explain how to create and display a flash message in a Flask app.
Think about what you do in the Python code and what you do in the HTML template.
You got /4 concepts.
    Why is setting a secret key important when using flash messages in Flask?
    Consider how Flask keeps session data safe.
    You got /4 concepts.