vatsalay
vatsalay

Reputation: 509

how to create drop down field in flask wtf

i want to create drop down menu's using flask wtforms. i have found drop down's in bootstrap 4 but i am unable to use it. i want to make it using flask wtf. here's what i want to achieve:

<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>

Upvotes: 1

Views: 4576

Answers (1)

J&#252;rgen Gmach
J&#252;rgen Gmach

Reputation: 6123

wtforms offers the SelectField

see docs https://wtforms.readthedocs.io/en/2.3.x/fields/#wtforms.fields.SelectField

Example (from the docs)

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

Upvotes: 1

Related Questions