今晚我遇到了这个问题,并最终解决了这个问题。我希望这对将来的人有帮助。
RecipeForm.py
class RecipeForm(Form): category = SelectField('Category', choices=[], coerce=int) ...views.py
@mod.route('/recipes/create', methods=['POST'])def validateRecipe(): categories = [(c.id, c.name) for c in g.user.categories.order_by(Category.name).all()] form = RecipeForm(request.form) form.category.choices = categories ...@mod.route('/recipes/create', methods=['GET'])def createRecipe(): categories = [(c.id, c.name) for c in g.user.categories.order_by(Category.name).all()] form = RecipeForm(request.form) form.category.choices = categories return render_template('recipes/createRecipe.html', form=form)


