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?
✗ Incorrect
The
flash() function is the built-in Flask method to create flash messages.Where do flash messages get stored temporarily in Flask?
✗ Incorrect
Flash messages are stored in the user's session, which requires a secret key.
How do you retrieve flash messages in a Flask template?
✗ Incorrect
The
get_flashed_messages() function returns all flash messages for display.What must you set in your Flask app to enable flash messages?
✗ Incorrect
Setting
app.secret_key is required to securely sign session data including flash messages.Flash messages are best used for:
✗ Incorrect
Flash messages provide temporary feedback to users, such as success or error notices.
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.