Thursday, March 29, 2012

Re: Can I POST edit form to detail view, and redirect back if invalid?

You're correct: HTTP does not allow you to, say, send POST data along
in a 30X (redirect) response [1]. You can redisplay the form at your
object's URL, but in order to actually do an HTTP redirect back to the
form URL, you'd have to pass the form data along in the URL query
string or store it on the session or something. The easiest thing to
do in most cases is to POST to the /edit/ URL and redirect to the
detail page (or somewhere else) if valid. This is what the [Create|
Update]View classes do. Could you provide a little more context on
why this is infeasible in your code? Maybe an snippet?

- Mjumbe

[1] http://www.w3.org/Protocols/rfc2616/rfc2616-sec10.html#sec10.3

On Mar 29, 7:49 am, Hemebond <hemeb...@gmail.com> wrote:
> I don't see anything on there that deals with transferring an
> redirecting with POST data. Is there a particular section that covers
> this?
>
> To be honest, I'm not sure if HTTP really supports what I'm trying to
> do, let alone Django.
>
> On Mar 30, 12:32 am, Joel Goldstick <joel.goldst...@gmail.com> wrote:
>
>
>
>
>
>
>
> > On Thu, Mar 29, 2012 at 7:13 AM, Hemebond <hemeb...@gmail.com> wrote:
> > > What can I pass back to the edit form view that already contains the
> > > values and errors and how? Posting to the edit form view would work
> > > but that would re-process the form.
>
> > > On Mar 30, 12:06 am, Joel Goldstick <joel.goldst...@gmail.com> wrote:
> > >> On Thu, Mar 29, 2012 at 6:33 AM, Hemebond <hemeb...@gmail.com> wrote:
> > >> > I want to use the URL of an object (a detail view) as the destination
> > >> > for CRUD operations. I want it to be able to accept GET, POST and
> > >> > DELETE requests.
>
> > >> > As part of this, I want the edit form (retrieved by appending /edit/
> > >> > to the object URL) to submit to the object URL. If the form is
> > >> > invalid, I then need to redirect back to the edit form, and display
> > >> > the errors.
>
> > >> > Is this possible? Is there a way to redirect back to the edit form
> > >> > with the new values and the errors that occurred during processing?
>
> > >> yes
>
> > You need to look at form handling in django.  Here is a good starting
> > point:http://www.djangobook.com/en/2.0/chapter07/
>
> > Then look at model forms.
>
> > --
> > Joel Goldstick

--
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 django-users+unsubscribe@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/django-users?hl=en.

No comments:

Post a Comment