Book Image

Learning Flask Framework

Book Image

Learning Flask Framework

Overview of this book

Table of Contents (17 chapters)
Learning Flask Framework
Credits
About the Authors
About the Reviewers
www.PacktPub.com
Preface
Index

Chapter 4. Forms and Validation

In this chapter, we will learn how to use forms to modify the content on our blog directly through the site. This will be a fun chapter because we will be adding all sorts of new ways to interact with our site. We will create forms for working with the Entry model, learn how to receive and validate user data, and finally update the values in the database. Form processing and validation will be handled by the popular WTForms library. We will continue building out views and templates to support these new forms, learning a few new Jinja2 tricks along the way.

In this chapter we shall:

  • Install WTForms and create a form for working with the Entry model

  • Write views to validate and process form data, and persist changes to the database

  • Create templates to display forms and validation errors

  • Use Jinja2 macros to encapsulate complex template logic

  • Display flash messages to the user

  • Create an image uploader and learn how to securely handle file uploads

  • Learn how to store and...