views:

92

answers:

1

The above mentioned things are giving me almost the same results was wondering whats the main difference in them.

+7  A: 

response = HttpResponse("Here's the text of the Web page.") will create a new HttpResponse object with HTTP code 200 (OK), and the content passed to the constructor. In General, you should only use this for really small responses (like an AJAX form return value, if its really simple - just a number or so).

HttpResponseRedirect("http://example.com/") will create a new HttpResponse object with HTTP code 302 (Found/Moved temporarily). This should be used only to redirect to another page (e.g. after successful form POST)

from the docs:

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.

enough said...

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.

is a call to render a template with given dictionary of variables to create the response for you. This is what you should be using most of the time, because you want to keep your presentation logic in templates and not in code.

Ofri Raviv
render_to_response should not be used after processing POSTs. After POST processing a redirect is a better choice because it won't display the message saying the form will be resubmitted.
celopes
I actually wrote that in my answer... I will bold it.
Ofri Raviv
Thanks mate for the detailed answer :)
Fahim Akhter