On Sep 18, 4:26 pm, WillF <[EMAIL PROTECTED]> wrote:
> What is the difference between httpresponseredirect and render_to_response?
> When should I use which?

If you're familiar with how HTTP works, it should be enough for me to
point out that HttpResponseRedirect returns a 302 with a Location
header.  If not, I'll explain that HttpResponseRedirect tells the
browser to go to a different URL.  It doesn't actually render
anything.  In contrast, render_to_response will output data for the
browser to render.

In most circumstances, you'll be rendering a response.  There are two
common situations when you'll want to tell the browser to redirect.
One, as Rajesh pointed out, is following a successful POST that you
want to make sure the user doesn't accidentally repeat.  The other is
when a URL changes and you want the user to end up at the current URL.

It might be useful to look at, e.g., create_object here:
http://code.djangoproject.com/browser/django/trunk/django/views/generic/create_update.py

You'll notice that it renders the template in every circumstance
except when the method is POST and the form is valid, in which case it
redirects.  That pattern is typical.

--
Brian
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to