【问题标题】:Flask - getting the text inside an html select option tag instead of the value of the optionFlask - 获取 html 选择选项标签内的文本而不是选项的值
【发布时间】:2017-08-10 14:35:45
【问题描述】:

我的表单中有一个选择标签

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

虽然这些值用于对选项进行排序,但我感兴趣的是选项中的文本。

然而,在python代码中,

source = request.form['source']

更喜欢这个值。 我怎样才能取回标签内的文本呢?

【问题讨论】:

  • 你可以保持值和文本相同

标签: python html flask


【解决方案1】:

可以有多种解决方案。尝试实现其中一种,看看是否有效

 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]

【讨论】:

  • 您能解释一下如何使用数据属性在 3 选项中执行此操作吗?
猜你喜欢
  • 2015-09-21
  • 1970-01-01
  • 1970-01-01
  • 2021-08-26
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2014-07-19
相关资源
最近更新 更多