简体   繁体   中英

Django testing. Status 200 and 302

How this work? what is the difference between 302 and 200? What is correctly?

def test_thanks_page(self):
    response = self.client.get('/thanks/')
    self.failUnlessEqual(response.status_code, 302)

And what is difference between:

self.failUnlessEqual(response.status_code, 302)

and

self.assertEqual(response.status_code, 302)

I believe 302 ("moved temporarily") indicates a redirect to another location (with it's URI coming back with the response), while 200 indicates that you got the resource you asked for in the URI you requested.

The W3 Status code definitions says:

For 302: "The requested resource resides temporarily under a different URI."

I hope this helped.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM