如何在烧瓶wtf中创建下拉字段

时间:2020-09-04 10:07:44

标签: python flask dropdown flask-wtforms

我想使用烧瓶wtforms创建下拉菜单。我在引导程序4中找到了下拉菜单,但我无法使用它。我想用烧瓶wtf制成。 这是我想要实现的目标:

<link href="https://stackpath.bootstrapcdn.com/bootstrap/4.4.1/css/bootstrap.min.css" rel="stylesheet"/>
<form class="" action="index.html" method="post">
  <div class="form-group">
    <label for="exampleFormControlSelect1">Example select</label>
    <select class="form-control" id="exampleFormControlSelect1">
      <option>1</option>
      <option>2</option>
      <option>3</option>
      <option>4</option>
      <option>5</option>
    </select>
  </div>
</form>

1 个答案:

答案 0 :(得分:0)

wtforms提供了SelectField

查看文档 https://wtforms.readthedocs.io/en/2.3.x/fields/#wtforms.fields.SelectField

示例(来自文档)

class PastebinEntry(Form):
    language = SelectField(u'Programming Language', choices=[('cpp', 'C++'), ('py', 'Python'), ('text', 'Plain Text')])