Web applications frequently redirect users following state-changing operations (such as login, registration, or profile updates) according to the Post/Redirect/Get (PRG) pattern. Because HTTP is stateless, transmitting feedback messages across redirects requires session storage.
Flask provides a lightweight, built-in mechanism called Flashing to record a message in the session and consume it on the next rendered page.
flash(message, category):return redirect(...)).get_flashed_messages():Use get_flashed_messages(with_categories=True) in your master base.html layout so messages render consistently across every page on your site:
In specific modular templates, you may want to extract only messages of a single category:
get_flashed_messages() to receive tuples of (category, message)?get_flashed_messages() during page rendering?Continue learning with hands-on practice, examples, and exercises in the upcoming topic.
| Previous Lesson | Next Lesson |
|---|---|
| Custom Form Validators & Secure File Uploads | Flask-SQLAlchemy Setup & Engine Configuration |
Test your understanding of this lesson with 5 questions. Each question has one correct answer.
Practice in live mentor-led sessions with real projects, mock tests, and verifiable certification at MSK Institute.