Flask-SQLAlchemy check if row exists in table

前端 未结 5 2042
耶瑟儿~
耶瑟儿~ 2020-12-05 02:17

I have a Flask application which uses Flask-SQLAlchemy to connect to a MySQL database.

I would like to be able to check whether a row is present in a table. How woul

5条回答
  •  -上瘾入骨i
    2020-12-05 02:58

    bool(User.query.filter_by(name='John Smith').first())
    

    It will return False if objects with this name doesn't exist and True if it exists.

提交回复
热议问题