how to use QuerySelectField in flask?

后端 未结 2 1406
情书的邮戳
情书的邮戳 2020-12-06 06:31

I am trying to have a select field filled with the results of a sqlalchemy request in a flask form.

Here are the code :

def possible_book():
    retu         


        
2条回答
  •  感动是毒
    2020-12-06 07:20

    One possible problem is that wtforms.ext.sqlalchemy.fields.QuerySelectField expects a SQLAlchemy query object, not a materialized list. Simply remove the all() call from your possible_book return to return an unmaterialized query to WTForms:

    def possible_book():
        return Book.query.with_entities(Book.id)
    

提交回复
热议问题