Flask Tutorial
About Lesson

In this Flask Tutorial we are going to learn about Flash Messages in Flask, good applications and user interfaces are all about feedback. If the user does not get enough feedback they will probably end up hating the application. Flask provides a really simple way to give feedback to a user with the flashing system. The flashing system basically makes it possible to record a message at the end of a request and access it next request and only next request. This is usually combined with a layout template that does this. Note that browsers and sometimes web servers enforce a limit on cookie sizes. This means that flashing message that are too large for session cookies causes message flashing to fail silently.

 

 

 

OK we are going to use our Flask Project from the previous lesson, where we have a login form, so now i want when a user enter wrong password or username, i want to show error in Flask Flash Messages.

 

 

This is our form.py file.

 

 

And this is our app.py file with our required view functions and you can see that we have also added our login view function in here. so in the Login view function we need to write our Flask Flash Messages, till now we haven’t learned about database functionality in Flask, we are going to just manually check the username and password. make sure that you have imported the flash message.

 

 

 

This is the complete code for app.py file.

 

 

We are going to show our Flask Flash Messages in login.html, so you can use this code for showing the Flash Messages, also we have added a simple bootstrap design for our flash message.

 

 

 

This is our complete code for login.html.

 

 

These are the rest of the files for the project.

 

templates/base.html

 

 

 

templates/index.html

 

 

templates/contact.html

 

 

templates/about.html

 

 

templates/500.html

 

 

templates/404.html

 

 

 

Run your flask project give wrong username and password you will see the error.

Flask Tutorial - Flash Messages in Flask
Flask Tutorial – Flash Messages in Flask