Bird
0
0

Which of the following is the correct way to send a 302 redirect response in a REST API using Python Flask?

easy📝 Syntax Q3 of 15
Rest API - HTTP Status Codes
Which of the following is the correct way to send a 302 redirect response in a REST API using Python Flask?
Areturn redirect('http://example.com', code=301)
Breturn redirect('http://example.com', code=302)
Creturn Response('Redirect', status=404)
Dreturn Response('Redirect', status=200)
Step-by-Step Solution
Solution:
  1. Step 1: Identify Flask redirect syntax

    Flask's redirect() function sends a redirect with specified status code.
  2. Step 2: Match status code 302 for temporary redirect

    Code 302 is for temporary redirect, 301 is permanent, 404 and 200 are incorrect here.
  3. Final Answer:

    return redirect('http://example.com', code=302) -> Option B
  4. Quick Check:

    Flask redirect with 302 = redirect(url, code=302) [OK]
Quick Trick: Use redirect(url, code=302) for temporary redirects in Flask [OK]
Common Mistakes:
MISTAKES
  • Using wrong status code in redirect function
  • Returning 404 or 200 instead of redirect status
  • Not specifying the code parameter in redirect

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Rest API Quizzes