Python Flask WTForm Demo: SelectField (Drop-down select)

Thomas Blum
Thomas Blum
3.3 هزار بار بازدید - 12 ماه پیش - In this video we add
In this video we add to our simple Python-Flask application that uses a WT-Form. We add a SelectField (drop-down select) to the form which already included a StringField (text input) and SubmitField (submit input). The flask/route portion did not change.  The HTML pages that are rendered are altered by adding references to the SelectField content but that looks no different than the StringField code leading to the text input. The bigger change is the WTF portion of the code which uses the SelectField method with two arguments.  The first argument represents that label for the select that will appear in the HTML. The second argument is a list of tuples. Each tuple has two components: one will be the option's value and the other will be placed between the open-option and the close-option tags (that is, what the user will see when viewing the form page.) Both HTML files (form and form handler) extend a shared HTML layout file which in turn links to a cascading style sheet (css) file.  We added some specific styling for the options in the drop-down selects. We show that the value passed to the form handler can be used to set an attribute of the handler HTML page.
12 ماه پیش در تاریخ 1402/04/23 منتشر شده است.
3,398 بـار بازدید شده
... بیشتر