返回HttpResponse(“”)的含义

时间:2018-09-06 10:15:29

标签: python django

在python中,如果用函数编写,以下代码的含义是什么

headers: {
    "Access-Control-Allow-Origin" = "*";
    "Cache-Control" = "no-cache";
    Connection = "keep-alive";
    "Content-Length" = 72;
    "Content-Type" = "application/json; charset=utf-8";
    Date = "Thu, 06 Sep 2018 09:50:55 GMT";
    Duration = "0.434662";
    "QB-Token-ExpirationDate" = "2018-09-06 11:50:52 +0000";
    "QuickBlox-REST-API-Version" = "0.1.1";
    Server = "nginx/1.8.1";
    "Set-Cookie" = "_mkra_ctxt=0ba5f09e90b9d6de33bac4aeced2046e--422; 
path=/; max-age=5; HttpOnly; secure";
    Status = "422 Unprocessable Entity";
    "Strict-Transport-Security" = "max-age=31536000";
    "X-Content-Type-Options" = nosniff;
    "X-Frame-Options" = SAMEORIGIN;
    "X-Request-Id" = "2420b421-6a3e-4433-8010-bdd82e6c8a9a";
    "X-Runtime" = "0.031619";
    "X-XSS-Protection" = "1; mode=block";
}
error: Request failed: client error (422)
reasons: {
    errors =     {
        message =         (
            "can't be blank",
            "Should contain 'payload' key"
        );
    };
}

1 个答案:

答案 0 :(得分:5)

所有Django views必须返回HTTP响应。

HttpResponse("")是在Django中返回响应的最简单方法。它没有任何内容,因为""是一个空字符串)。

这不是一个非常有用的代码行,大多数时候,您只会临时使用它来使视图工作,然后将其替换为更有用的东西。如果您想设置自动监视以检查Django网站是否正在运行,可以使用它。