0
0
Flaskframework~10 mins

Querying with filter and filter_by in Flask - Interactive Code Practice

Choose your learning style9 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete the code to query all users with the name 'Alice' using filter_by.

Flask
users = User.query.[1](name='Alice').all()
Drag options to blanks, or click blank then click option'
Aget
Bfilter
Call
Dfilter_by
Attempts:
3 left
💡 Hint
Common Mistakes
Using filter instead of filter_by with keyword arguments.
Using get which fetches by primary key.
2fill in blank
medium

Complete the code to query users whose age is greater than 30 using filter.

Flask
users = User.query.[1](User.age > 30).all()
Drag options to blanks, or click blank then click option'
Afilter
Bfilter_by
Cget
Dorder_by
Attempts:
3 left
💡 Hint
Common Mistakes
Using filter_by with expressions causes errors.
Using order_by instead of filter for filtering.
3fill in blank
hard

Fix the error in the code to query users with email ending with '@example.com'.

Flask
users = User.query.[1](User.email.like('%@example.com')).all()
Drag options to blanks, or click blank then click option'
Afilter
Bfilter_by
Cget
Dorder_by
Attempts:
3 left
💡 Hint
Common Mistakes
Using filter_by with expressions causes runtime errors.
Using get which fetches by primary key only.
4fill in blank
hard

Fill both blanks to query users with age less than 25 and name 'Bob'.

Flask
users = User.query.[1](User.age [2] 25, User.name == 'Bob').all()
Drag options to blanks, or click blank then click option'
Afilter
Bfilter_by
C<
D>
Attempts:
3 left
💡 Hint
Common Mistakes
Using filter_by with expressions causes errors.
Using greater than operator instead of less than.
5fill in blank
hard

Fill all three blanks to query users with name starting with 'A', age greater than 20, and order by age descending.

Flask
users = User.query.[1](User.name.like('A%'), User.age [2] 20).[3](User.age.desc()).all()
Drag options to blanks, or click blank then click option'
Afilter
B>
Corder_by
Dfilter_by
Attempts:
3 left
💡 Hint
Common Mistakes
Using filter_by instead of filter for expressions.
Using less than operator instead of greater than.
Not using order_by for sorting.