简体   繁体   English

Django测试。 状态200和302

[英]Django testing. Status 200 and 302

How this work? 这怎么工作? what is the difference between 302 and 200? 302和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. 我相信302(“暂时移动”)表示重定向到另一个位置(带有响应的URI返回),而200表示您在请求的URI中获得了您要求的资源。

The W3 Status code definitions says: W3状态代码定义说:

For 302: "The requested resource resides temporarily under a different URI." 对于302:“请求的资源暂时驻留在不同的URI下。”

I hope this helped. 我希望这有帮助。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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