答案 0 :(得分:0)
如果在创建时将值传递给表单,则在呈现后将在HTML表单中选择该值,您不需要将其作为选项传递。
import flask
from flask_wtf import FlaskForm
from jinja2 import Template
from wtforms import SelectField
class CategoryForm(FlaskForm):
category = SelectField(choices=[('','') , ("category 1","category 1"),("category 2","category 2")])
class Meta:
csrf = False
def index():
cf = CategoryForm(category="category 1")
return flask.render_template(
Template("""
<html>
<body>
<form method="POST">
{{form.category()}}
<input type="submit">
</form>
</body>
</html>
"""),
form=cf)