【问题标题】:Populate Bootstrap Dropdown Button from CSV/Flask从 CSV/Flask 填充引导下拉按钮
【发布时间】:2018-10-02 14:08:47
【问题描述】:

我正在尝试让我的烧瓶应用程序显示我的数据库中存储在 csv 中的类别列表。类别列存在于我调用列表的 CSV 中,然后尝试显示在引导下拉按钮上。来自烧瓶:

@app.route('/')
def test():

    data= df['categories'].tolist()
    return render_template('test.html', data= data)

从那里,我获取变量数据并将其注入 Bootstrap 下拉菜单按钮:

<div class="dropdown-menu" aria-labelledby="dropdownMenuButton">
      <select name= "datum" method="GET" action="/">
          {% for datum in data[1:] %}
             <option value= "{{datum}}">{{datum}}</option>"
          {% endfor %}
       </select>
       <a class="dropdown-item" href="#">{{data}}</a>
       <a class="dropdown-item" href="#">Another action</a>
       <a class="dropdown-item" href="#">Something else here</a>
 </div>

第一个按钮是我想要的,但它是按钮中的一个按钮。当我单击它时它也会消失并且没有任何输入。

【问题讨论】:

    标签: html css twitter-bootstrap flask


    【解决方案1】:

    您正在尝试在 droDown 按钮内添加一个选择,我设计该按钮以在 &lt;a&gt; 标记中显示选项。

    请尝试以下代码:

    <div class="dropdown">
            <button class="btn btn-secondary dropdown-toggle" type="button" id="dropdownMenuButton" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
                Select
            </button>
            <div class="dropdown-menu" aria-labelledby="dropdownMenuButton">
                {% for datum in data[1:] %}
                <a class="dropdown-item" href="#">{{datanum}}</a>
                {% endfor %}
            </div>
        </div>
    

    &lt;/option&gt; 结束标记之后还有一个 ",但它与问题无关。

    【讨论】:

      猜你喜欢
      • 2021-04-10
      • 1970-01-01
      • 2017-01-13
      • 1970-01-01
      • 2013-05-10
      • 1970-01-01
      • 1970-01-01
      • 2015-04-06
      • 2015-12-22
      相关资源
      最近更新 更多