Bird
0
0

Given this Flask test code snippet, what will response.status_code be if the form data is valid and the route returns redirect('/success')?

medium📝 Predict Output Q4 of 15
Flask - Testing Flask Applications
Given this Flask test code snippet, what will response.status_code be if the form data is valid and the route returns redirect('/success')?
response = client.post('/submit', data={'username': 'testuser'})
A200
B404
C500
D302
Step-by-Step Solution
Solution:
  1. Step 1: Understand what redirect() returns in Flask

    The redirect() function returns a response with status code 302, which means a redirect.
  2. Step 2: Apply this to the test client response

    When the test client posts valid data and the route calls redirect('/success'), the response status code will be 302.
  3. Final Answer:

    302 -> Option D
  4. Quick Check:

    redirect() response code = 302 [OK]
Quick Trick: redirect() returns status code 302 in Flask [OK]
Common Mistakes:
MISTAKES
  • Assuming redirect returns 200
  • Confusing 404 with redirect
  • Expecting 500 without error

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Flask Quizzes