0PricingLogin
Flask Academy · Lesson

Fetch Rows with query and get

Retrieve all, one, or by primary key.

Reading Starts With query

Every read from your database begins with the model's query attribute. It is your gateway to fetching rows as Python objects. 🔎

rows = User.query

Grab Everything with all

Call all() on a query to load every matching row into a plain Python list you can loop over.

users = User.query.all()
for u in users:
    print(u.name)

All lessons in this course

  1. Fetch Rows with query and get
  2. Filter, Order, and Limit Results
  3. Define Relationships and Foreign Keys
  4. Joins and Lazy vs Eager Loading
← Back to Flask Academy