如何在 flask wtf 中创建下拉字段
how to create drop down field in flask wtf
我想使用 Flask wtforms 创建下拉菜单。我在 bootstrap 4 中找到了下拉菜单,但我无法使用它。我想用 flask 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>
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')])
我想使用 Flask wtforms 创建下拉菜单。我在 bootstrap 4 中找到了下拉菜单,但我无法使用它。我想用 flask 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>
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')])