Bird
0
0

Given this Flask route:

medium📝 component behavior Q5 of 15
Flask - Ecosystem and Patterns
Given this Flask route:
@app.route('/profile/')
def profile(user_id):
    profile_data = profile_service.fetch_profile(user_id)
    if profile_data is None:
        return 'Profile not found', 404
    return profile_data

What will the route return if fetch_profile returns None?
AA 500 Internal Server Error
BA 404 response with 'Profile not found'
CAn empty JSON response
DA redirect to the homepage
Step-by-Step Solution
Solution:
  1. Step 1: Analyze the route logic

    The route checks if profile_data is None.
  2. Step 2: Determine the response

    If None, it returns 'Profile not found' with status code 404.
  3. Final Answer:

    A 404 response with 'Profile not found' -> Option B
  4. Quick Check:

    None triggers 404 response [OK]
Quick Trick: None return triggers 404 response [OK]
Common Mistakes:
MISTAKES
  • Assuming None causes 500 error
  • Expecting empty JSON instead of error message
  • Thinking it redirects automatically

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Flask Quizzes