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

Getting started with WTForms


WTForms is a popular choice for form processing and validation in the Flask community. It uses a declarative approach to building forms (similar to how we defined our SQLAlchemy models), and supports a variety of different field types and validators.

Note

At the time of writing this book, WTForms 2.0 is still a development release, but should be the official release shortly. For that reason we will be using version 2.0 in this book.

Let's get started by installing WTForms into our blog project virtualenv:

(blog) $ pip install "wtforms>=2.0"
Successfully installed wtforms
Cleaning up...

We can verify that the installation succeeded by opening up a shell and checking the project version:

(blog) $ ./manage.py shell
In [1]: import wtforms

In [2]: wtforms.__version__
Out[2]: '2.0dev'

My version shows the development release since 2.0 has not been officially released yet.

Defining a form for the Entry model

Our goal is to be able to create and edit blog entries directly...