Flask Flashing
Python Flash
- flash () - It is used to generate informative messages in the flask. It creates a message in one view and renders it to a template view function called next.
- flash() method of the flask module passes the message to the next request which is an HTML template.
Syntax
Flash Syntax
- Category - It is an optional parameter which may represent any error, information, or warning ?
- Message - It is the message to be flashed to the user.
The messages are generated in the flask script using the flash() method of flask module. These messages need to be extracted in the template from the session. For this case, the method get_flashed_messages() is called in the HTML template.
Syntax
Flashed
get_flashed_messages (with_categories, category_filter)
- with_categories: This parameter is optional and used if the messages have the category.
- category_filter: This parameter is also optional. It is useful to display only the specified messages.
Sample code
The following code contains the flask and HTML scripts for server and client-side scripting.
flashing.py
index.html
login.html
Read Also
Output
- The URL /index displays the following template (index.html) which contains the code for flashing the message. The link login redirects the user to the URL /login.
Flash Home
- The following page shows the template login.html. The user to enter the valid email id and password. Here, if the user enters any wrong password other than "123", it can not be able to login to the application.
Flash Login
- The script login.py generates an error message as "invalid password" and redirects the user to this page itself.
Flash invalid
- The second case where the user has entered the correct password as 123 and the script flashing.py flashes the success message.
Flash Logged
If you want to learn about Python Course , you can refer the following links Python Training in Chennai , Machine Learning Training in Chennai , Data Science Training in Chennai , Artificial Intelligence Training in Chennai