This is a question upon the use of wtforms SelectField
.
Once the form submitted, I wish to extract selected text.
I have the following form:
When you set your choices, the list looks like [(index, value),...]
so you don't need to import it, and probably shouldn't if setting dynamically
value = dict(form.hour.choices).get(form.hour.data)
Substitute self for form if inside form class
In general, I often zip the choices so index and value are the same. However, sometimes I want to present a displayed selection that's shorter than the value of interest. In that case, I think of it like [(value, display),...]
and then the data variable is the value of interest. For example, [(abspath, basename), ...]