def showcart(request, style_id, choice_id):
s = Style.objects.get(id=style_id)
c = Choice.objects.get(id=choice_id)
x = request.session ?? # I want to add s and c to my session?
return render_to_response('show_test.html', {'mychoice': x})
//////
Everytime the user adds something to their shopping cart then this
view will be accessed. I want the view to store the two parameters (s
and c) into my request.session so that the data in the session can be
showed when the website visitor checks out. However, I'm not sure how
to add these parameters to my session variable. I'm also not sure how
to display all the session data.
Thanks for any help
cart = request.session.get('cart', [])
cart.append({'style':s,'choice'c})
request.session['cart']=cart
But, fundamentally, putting cart info in session is a bad idea; people
switch computers (and thus cookies; sessions) fairly often. Also,
people delete cookies for good reasons. I'd be severely pissed if my
amazon wishlist went away when I deleted cookies.
> I'm also not sure how
> to display all the session data.
http://www.djangoproject.com/documentation/authentication/#authentication-data-in-templates
http://www.djangoproject.com/documentation/templates_python/#subclassing-context-requestcontext
http://www.djangoproject.com/weblog/2005/sep/24/newshortcuts/
On Thu, 19 Jul 2007 10:45:46 -0500
"Jeremy Dunck" <jdu...@gmail.com> wrote:
>
> On 7/19/07, Greg <gms...@hotmail.com> wrote:
> > x = request.session ?? # I want to add s and c to my session?
>
> cart = request.session.get('cart', [])
> cart.append({'style':s,'choice'c})
>
> request.session['cart']=cart
>
> But, fundamentally, putting cart info in session is a bad idea; people
> switch computers (and thus cookies; sessions) fairly often. Also,
> people delete cookies for good reasons. I'd be severely pissed if my
> amazon wishlist went away when I deleted cookies.
but was is the solution if the user is not logged in ?
At this point your only chance is a session bound cookie or I'm wrong ?
Kindly regards
Lutz Steinborn
On Jul 19, 11:40 am, Lutz Steinborn <l.steinb...@4c-ag.de> wrote:
> Hi Jeremy,
>
> On Thu, 19 Jul 2007 10:45:46 -0500
>
> "Jeremy Dunck" <jdu...@gmail.com> wrote:
>
No, don't do that. The session framework already does that for you.
If you use request.session, and the browser accepts cookies, you'll
magically have values in request.session as set on previous requests.