Django: What is the difference b/w HttpResponse vs HttpResponseRedirect vs render_to_response
上面提到的东西给了我几乎相同的结果,想知道它们之间的主要区别是什么。
将使用HTTP代码200(OK)创建一个新的
将使用HTTP代码302(临时找到/移动)创建一个新的
从文档中:
class HttpResponseRedirect
The constructor takes a single argument -- the path to redirect to.
This can be a fully qualified URL
(e.g. 'http://www.yahoo.com/search/')
or an absolute URL with no domain
(e.g. '/search/'). Note that this
returns an HTTP status code 302.
足够说...
render_to_response(template[, dictionary][, context_instance][,mimetype])
Renders a given template with a given context dictionary and returns
an HttpResponse object with that
rendered text.
是调用以使用给定的变量字典呈现模板来为您创建响应的调用。这是您大多数时候应该使用的方式,因为您希望将表示逻辑保留在模板中,而不是在代码中。