Book Image

Flask Framework Cookbook

By : Shalabh Aggarwal
Book Image

Flask Framework Cookbook

By: Shalabh Aggarwal

Overview of this book

Table of Contents (19 chapters)
Flask Framework Cookbook
Credits
About the Author
About the Reviewers
www.PacktPub.com
Preface
Index

Flashing messages for better user feedback


An important part of all good web applications is to give users feedback about various activities. For example, when a user creates a product and is redirected to the newly created product, then it is a good practice to tell the user that the product has been created.

Getting ready

We will be adding the flash messages functionality to our existing catalog application. We also have to make sure that we add a secret key to the application, because the session depends on the secret key, and in the absence of the secret key, the application will error out while flashing.

How to do it…

To demonstrate the flashing of messages, we will flash messages on the creation of products. First, we will add a secret key to our app configuration in flask_catalog_template/my_app/__init__.py:

app.secret_key = 'some_random_key'

Now, we will modify our create_product() handler in flask_catalog_template/my_app/catalog/views.py to flash a message to the user about the product...