Book Image

Flask Framework Cookbook - Second Edition

By : Shalabh Aggarwal
Book Image

Flask Framework Cookbook - Second Edition

By: Shalabh Aggarwal

Overview of this book

Flask, the lightweight Python web framework, is popular thanks to its powerful modular design that lets you build scalable web apps. With this recipe-based guide, you’ll explore modern solutions and best practices for Flask web development. Updated to the latest version of Flask and Python 3, this second edition of Flask Framework Cookbook moves away from some of the old and obsolete libraries and introduces new recipes on cutting-edge technologies. You’ll discover different ways of using Flask to create, deploy, and manage microservices. This Flask Python book starts by covering the different configurations that a Flask application can make use of, and then helps you work with templates and learn about the ORM and view layers. You’ll also be able to write an admin interface and get to grips with debugging and logging errors. Finally, you’ll learn a variety of deployment and post-deployment techniques for platforms such as Apache, Tornado, and Heroku. By the end of this book, you’ll have gained all the knowledge you need to confidently write Flask applications and scale them using standard industry practices.
Table of Contents (15 chapters)

What this book covers

Chapter 1, Flask Configurations, explains the different ways in which Flask can be configured to suit the various needs of any project. It starts by telling us how to set up our development environment and moves on to the various configuration techniques.

Chapter 2, Templating with Jinja2, covers the basics of Jinja2 templating from the perspective of Flask and explains how to make applications with modular and extensible templates.

Chapter 3, Data Modeling in Flask, deals with one of the most important parts of any application, that is, its interaction with database systems. We will see how Flask can connect to database systems, define models, and query databases for the retrieval and feeding of data.

Chapter 4, Working with Views, talks about how to interact with web requests and the proper responses to these requests. It covers various methods of handling requests properly and designing them in the best way.

Chapter 5, Webforms with WTForms, covers form handling, which is an important part of any web application. As much as the forms are important, their validation holds equal importance, if not more. Presenting this information to the users in an interactive fashion adds a lot of value to the application.

Chapter 6, Authenticating in Flask, deals with authentication, which sometimes acts as a thin red line between the application being secure and insecure. This chapter deals with multiple social and enterprise login techniques in detail.

Chapter 7, RESTful API Building, explains REST as a protocol and then discusses writing RESTful APIs for Flask applications using libraries, as well as completely customized APIs.

Chapter 8, Admin Interface for Flask Apps, focuses on writing admin views for Flask applications. First, we write completely custom-made views and then write them with the help of an extension.

Chapter 9, Internationalization and Localization, expands the scope of Flask applications and covers the basics of how to enable support for multiple languages.

Chapter 10, Debugging, Error Handling, and Testing, moves on from being completely development-oriented to testing our application. With better error handling and tests, the robustness of the application increases manifold, and debugging makes the lives of developers easier.

Chapter 11, Deployment and Post-Deployment, covers the various ways and tools with which the application can be deployed. Then, you will learn about application monitoring, which helps us to keep track of the performance of the application.

Chapter 12, Microservices and Containers, talks about building and deploying applications in a microservices pattern using tools such as Docker, Kubernetes, and AWS Lambda.

Chapter 13, Other Tips and Tricks, is a collection of some handy tricks that range from full-text search to caching. Then, finally, we will go asynchronous with certain tasks in Flask applications.