On 5/12/2009 5:45 AM, Iqbal Abdullah wrote:
> I'm confused on how to get data in request.session if a certain view
> redirects the user using HttpResponseRedirect()
>
> A sample code:
>
> def view_start(request):
> try:
> Member(id)
> except Exception, e:
> # redirect to registration page if this id is not
> registered
> template_path = "member/register.html"
>
> request.session['test_id'] = 200
>
> url = "/member/register/" # This url is processed by
> view_register()
> return HttpResponseRedirect(url)
>
> def view_register(request):
>
> test_id = request.session.get('test_id', None)
>
>
> in this case I will get None for test_id in view_register().
> Is it possible to pass along sessions data when we use
> HttpResponseRedirect() to redirect? Just from the code above I don't
> see how that's possible because request in view_start() didn't get
> passed anywhere when the redirect occurred.
>
> I searched through the discussions and found something exactly like
> what I'm doing (http://groups.google.com/group/django-users/
> browse_thread/thread/451abbaf1feccf0b/19f266af42f4ed62?
> hl=en&lnk=gst&q=sessions+HttpResponseRedirect#) and the OP says it's
> working for him, but I'm not seeing the same results. Can members
> point me to the right direction on how to use sessions through
> redirects?
Your code appears correct for how you're using `request.session`. Couple
things to check:
1. Make sure you've enabled your sessions[1].
2. Make sure you are getting the `sessionid` cookie in your browser.
[1]
<http://docs.djangoproject.com/en/dev/topics/http/sessions/#enabling-sessions>
--
George
--~--~---------~--~----~------------~-------~--~----~
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
-~----------~----~----~----~------~----~------~--~---