Flashing messages for better user feedback
An important aspect of all good web applications is to give users feedback regarding various activities. For example, when a user creates a product and is redirected to the newly created product, then it is good practice to tell them that the product has been created. In this recipe, we will see how flashing messages can be used as a good feedback mechanism for users.
Getting ready
We will start by adding the flash message 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 it, and if it’s absent, the application will error out while flashing.
How to do it...
To demonstrate the flashing of messages, we will flash messages upon a product’s creation.
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...