python - How to get value (not key) data from SelectField in WTForms -


this question has answer here:

i have wtf selectfield, , i'm trying store name of user's choice display on page.

given form is

choice = selectfield('choice', choices=[('cho_1', 'choice one'), ('cho2', 'choice two')]) 

i understand

self.choice = form.choice.data 

will me user's choice (say, cho_1), how value ("choice one")? feel it's simple dicts, various attempts plus googling/searching haven't helped far.

thanks ashish nitin patil directing me here.

i needed transform 'choices' dict, value key form.data, thus:

 value = dict(form.choice.choices).get(form.choice.data) 

Comments

Popular posts from this blog

python - RuntimeError: can't re-enter readline -

python - PyInstaller UAC not working in onefile mode -

ios - Pass NSDictionary from Javascript to Objective-c in JavascriptCore -