WTF stands for WT Forms which is intended to provide the interactive user interface for the user. The WTF is a built-in module of the flask which provides an alternative way of designing forms in the flask web applications.
Why WTF Useful?
WTF is useful due to the following factors.
- The form elements are sent along with the request object from the client side to the server side. Server-Side script needs to recreate the form elements since there is no direct mapping between the client side form elements and the variables to be used at the server side.
- There is no way to render the HTML form data at real time.
The WT Forms is a flexible, form rendering, and validation library used to provide the user interface.
To use the WT forms, we need to install the flask-wtf library which can be installed using pip installer.
The module contains a Form class which is considered as the parent class for all the form related operations.
The standard form fields are listed below.
||It is used to represent the text filed HTML form element.
||It is used to represent the checkbox HTML form element.
||It is used to represent the text field to display the numbers with decimals.
||It is used to represent the text field to display the integer values.
||It is used to represent the radio button HTML form element.
||It is used to represent the select form element.
||It is used to represent text area form element.
||It is used to take the password as the form input from the user.
||It provides represents the <input type = 'submit' value = 'Submit'> html form element.
Consider the following example.
In this example, we will create a form using flask WTF module. First, we will create a form class named as forms.py and we will import those form elements into the module formexample.py.