Python Flask WT-Forms Demo: Numeric Input (IntegerField and DecimalField)

preview_player
Показать описание
In this video we continue to demo basic WT-Forms in a Python-Flask app. This time we add numeric inputs. In WT-Forms this is accomplished with IntegerField and DecimalField, both of which result in HTML inputs of the numeric type when the form HTML is rendered. In the example the two new fields allow a user to enter an hourly wage and a number of hours worked in a week. In addition to displaying the information entered, it is used to calculate the weekly salary (including time-and-a-half for overtime hours exceeding 40 hours). We show how the calculation can be performed using Python as the routing Python/Flask passes the data from the form HTML to the handler HTML (the calculated salary is passed as an argument in render_template for the handler). We also show how the calculation can be performed using Jinja. The data must be cast into the appropriate type and we need an if control structure within Jinja to test whether the user worked overtime or not.
Рекомендации по теме