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

javascript - Clear button on addentry page doesn't work -

c# - Selenium Authentication Popup preventing driver close or quit -

tensorflow when input_data MNIST_data , zlib.error: Error -3 while decompressing: invalid block type -