Thank you DR.  For other newbies out there I changed my views to this
and it worked great:

articles = Context({'articles': Articles.objects.all()})

def order(request):
        if request.method == 'POST':
                form = OrderForm(request.POST)
                if form.is_valid():
                        current_order = form.save()
                        order_info = Context({'order_info': current_order})
                        request.session['order_info'] = order_info
                        return HttpResponseRedirect('/order_complete/')
        else:
                form = OrderForm()

        return render_to_response('order.html', {'form': form}, articles)

def order_complete(request):
        order_info = request.session['order_info']
        return render_to_response('order_complete.html', order_info,
articles)

On Dec 11, 9:30 am, Daniel Roseman <dan...@roseman.org.uk> wrote:
> On Dec 11, 3:13 pm, Andy <asdjohn...@gmail.com> wrote:
>
>
>
>
>
> > Thanks for the response Shawn.  I have done what you suggested,
> > assigning a variable named order_info and can use it if I use
> > render_to_response in my order view.  But I want to use
> > HttpResponseRedirect after the form is saved.  I'm thinking I need to
> > get the order_info variable into my order_complete view.  How can I do
> > this?
>
> > articles = Context({'articles': Articles.objects.all()})
>
> > def order(request):
> >         if request.method == 'POST':
> >                 form = OrderForm(request.POST)
> >                 if form.is_valid():
> >                         current_order = form.save()
> >                         order_info = Context({'order_info': current_order})
> >                         return render_to_response('order_complete.html', 
> > order_info,
> > articles) #this works
> >                         return HttpResponseRedirect('/order_complete/') 
> > #but this is what I
> > want to use
> >         else:
> >                 form = OrderForm()
>
> >         return render_to_response('order.html', {'form': form}, articles)
>
> > def order_complete(request): #how can I put order_info here?
> >         return render_to_response('order_complete.html', order_info,
> > articles)
>
> The order_complete view needs some way of knowing about the object
> you've just created. Obviously, it's in the database, so all you need
> to give that view is some way to identify it - eg by the id field.
>
> So you'll need to either pass it as a URL parameter to the
> order_complete view:
>     return HttpResponseRedirect('/order_complete/%s/' %
> current_order.id)
>
> or put it into the session when you save the form, and get it out
> again in the order_complete view. Obviously if there's any personal
> info involved, you should not use the first method, or at least add
> some extra authentication.
> --
> DR.

--

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


Reply via email to