- [Instructor] Hi, and welcome tothe last video of this section,Flask Flash Messages and Custom Error Pages.In the previous video, we learned how to use templatesfor creating webpages inside Flask.In this video, we are going to talk about flash messages,which are sent from server side to the template context.And we will see how to create and map custom error pages.First, let's check how we send flash messagesto the template context.Flash messages were designed toprovide feedback to the user.On this page, the two blue alerts are flash messages,and are generated by the template context.

Let's take a look at the source code that generates these.Now we open up the about.html file, and we can seethat this extends the layout of the HTML page.This helps us to have the menuand the footer region appear correctly on the page.The flash messages can be accessed usingthe get_flashed_messages method.Flash messages can have categories.The category filter name parameter helps to filter.Using this parameter only the messagespushed with the given category are returned.In the routes.py file,we can see how the two messagesare pushed to the template context.

The flash method from the Flask name spacetakes two parameters.The first parameter is the messageand the second is the category whichthe message should be assigned to.Now, let's check how to use custom error pages.In the web application we have two custom error pages.First is an error page shownwhen the user navigates to an unmapped URL.The source code for this errorpage is in file 404.html.The 404 HTML extends the layout that the HTML template.

We create the new Bootstrap jumbotronand release the flash messages inside that.The second error page is displayedwhen an internal error occurs on the server.Each of the error pages displays the error messagegenerated by the Flask frameworkinside the Bootstrap alert.The source code for this error pageis in the file 500.html.The source code for this file is very similarto the error file we have taken a look at at 404.html.Let's see how to define these custom errorpage handlers in the application.

Let's open up routes.py and let's navigateto the init error handlers method.Inside the init error handlers method we use theerror handlers spec dictionary to assign thehandler methods to the different error codes.This can be seen in the init error handlers.Besides using the error handlers spec dictionary,there's an annotation called error handlerwhich you see is on parameter,the error code which the methodshould be mapped to.In this video, we covered what are flash messagesand how we can use these.

We also covered how to map, createand use custom error pages.In this section, we covered how to createa new development environment for Flask.After that, we check how to configure rootsand handle request parameters.Then we learned how templates can beused for displaying webpages,and in the end, in this video,we covered flash messages and error pages.In the next section, we cover the Web API port in that.First, we will cover the basics of CRUD and REST.Then we will check how to SQLcoming for storing models,and after that, we will implementthe Create and Read API ports from CRUD.

Thank you for watching and see you in the next section.

Resume Transcript Auto-Scroll

Author

Released

10/4/2016

Note: Web API Development with Flask was created by Packt Publishing. It was originally released on 1/30/16. We are pleased to host this training in our library.

Regardless of platform, you will need to build APIs to serve data between different client applications and endpoints. Good APIs are a necessity for web and mobile projects, especially with the modern, mobile-first approach to development. This course delivers the fundamental knowledge required to enable highly connected interactions between applications via RESTful web APIs. Follow along with Gergo Bogdan and learn how to build up and structure an effective web API that can be used by any client application accessing it over HTTP, using Flask, the Python microframework.

Find out how to implement CRUD operations using SQLAlchemy and MySQL as the data store. Get an understanding of how REST works relative to APIs, and learn how to test APIs written in Python with the support of Flask. Explore token-based authentication and find out how to store passwords securely in your database. Along the way, Gergo introduces best practices and design guidelines when building large applications.