0PricingLogin
Flask Academy · Lesson

Filter, Order, and Limit Results

Use filter_by, order_by, and pagination.

Narrow Results with filter_by

Use filter_by() with keyword arguments to keep only rows that match a column exactly. It reads almost like English. 🎯

admins = User.query.filter_by(role="admin").all()

More Power with filter

When you need comparisons, reach for filter() and full column expressions instead of plain equality.

adults = User.query.filter(User.age >= 18).all()

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