简体   繁体   中英

Flask - getting the text inside an html select option tag instead of the value of the option

I have a select tag in my form

    <select name="source" id="source">
        {% for row in inode.inodes %}
            <option value="{{loop.index}}">{{ row.inode.title }}</option> 

While the values are used to order the options, what interests me is the text in the option.

however, in the python code,

source = request.form['source']

Is preferring the value. How can I retrieve the text inside the tag instead?

Muchas gracias

There can be multiple solutions to this.Try to implement one of these can see if it works

 1. You can keep value and text same
 2. Fetch value via jquery/js in frontend and then post it in variable to access them in flask
 3. Set data-attribute for options and send them to flask.[See here][1]

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM