On Fri, Dec 11, 2009 at 4:44 PM, Andy <[email protected]> wrote:
> 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)
This is the worst way to pass state. The state should be passed via
the user, rather than storing it in the session. Your view should look
something like this:
def order(request):
if request.method == 'POST':
form = OrderForm(request.POST)
if form.is_valid():
order = form.save()
return HttpResponseRedirect(reverse('order_complete', args=[order.id]))
else:
form = OrderForm()
return render_to_response('order.html', {'form': form}, articles)
def order_complete(request, order_id=None):
order = get_object_or_404(Order, id=order_id)
return render_to_response('order_complete.html', {'order': order}, articles)
Cheers
Tom
--
You received this message because you are subscribed to the Google Groups
"Django users" group.
To post to this group, send email to [email protected].
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.