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

preview_player
Показать описание
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.
Рекомендации по теме
Комментарии
Автор

this video deserves way more thumbs ups

Andrei-tj
Автор

thanks sir you explained every thing very nicely..

moyzahmed
Автор

Great Video, ty, any suggestions on how we can import a dynamic sql list rather than manually creating a list?
so, the below pulls through all students
student_names = Students.query.with_entities(Students.firstname, Students.surname).all()

legionnaire
Автор

Can you please tell me, I have create form on another file like you guys created but its not calling wen reading main function.. its work only create class on file . ♥

kmax
visit shbcf.ru