On Mar 7, 9:42 pm, Rex <rex.eastbou...@gmail.com> wrote:
> I'm reading the documentation on sessions (http://
> docs.djangoproject.com/en/dev/topics/http/sessions/?from=olddocs) and
> saw the following example:
>
> def post_comment(request, new_comment):
>     if request.session.get('has_commented', False):
>         return HttpResponse("You've already commented.")
>     c = comments.Comment(comment=new_comment)
>     c.save()
>     request.session['has_commented'] = True
>     return HttpResponse('Thanks for your comment!')
>
> "request" seems to be a local variable, so I would think that setting
>
> request.session['has_commented'] = True
>
> would have no effect, since that variable is not used again (e.g. not
> returned by the function). Does assigning a value in the
> request.session dictionary somehow send a cookie to the user's
> browser? I tested whether I could store a value in request.session in
> one view function and retrieve it in a subsequent view function, and
> that didn't work for me, as I had expected. Could somebody shed some
> light on this?

You obviously haven't read the documentation very closely, as it
explains in detail how sessions work, how they are related to cookies,
and where the data is stored.

Storing a value in one view and retrieving it in another is precisely
what sessions are for, so I don't know why your attempt didn't work,
except that you must not have followed the instructions in the
documentation.
--
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-users@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