Bird
0
0

In a Flask app using a service layer, where should database queries be placed?

easy📝 Conceptual Q2 of 15
Flask - Ecosystem and Patterns
In a Flask app using a service layer, where should database queries be placed?
AInside the service layer functions.
BDirectly inside route functions.
CIn the HTML templates.
DIn the static files folder.
Step-by-Step Solution
Solution:
  1. Step 1: Identify where business logic belongs

    Database queries are part of business logic and should be in the service layer.
  2. Step 2: Understand Flask structure

    Routes call service layer functions, which handle data access.
  3. Final Answer:

    Inside the service layer functions. -> Option A
  4. Quick Check:

    Database queries = Service layer [OK]
Quick Trick: Put queries in service layer, not routes [OK]
Common Mistakes:
MISTAKES
  • Placing queries in templates
  • Writing queries in static files
  • Putting queries directly in routes

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Flask Quizzes