Google Groups Home
Help | Sign in
do sessions work when redirecting?
There are currently too many topics in this group that display first. To make this topic appear first, remove this option from another topic.
There was an error processing your request. Please try again.
flag
  8 messages - Collapse all  -  Translate all to Translated (View all originals)
The group you are posting to is a Usenet group. Messages posted to this group will make your email address visible to anyone on the Internet.
Your reply message has not been sent.
Your post was successful
 
From:
To:
Cc:
Followup To:
Add Cc | Add Followup-to | Edit Subject
Subject:
Validation:
For verification purposes please type the characters you see in the picture below or the numbers you hear by clicking the accessibility icon. Listen and type the numbers you hear
 
Mike Chambers  
View profile  
 More options May 13 2008, 3:23 pm
From: Mike Chambers <mikechamb...@gmail.com>
Date: Tue, 13 May 2008 12:23:17 -0700
Local: Tues, May 13 2008 3:23 pm
Subject: do sessions work when redirecting?
I am running into an issue where my session values are not remembered if
I do an HTTP redirect.

If I do:

--
request.session['a'] = 'aaaa'
return HttpResponseRedirect(request.META['HTTP_REFERER']
--

The session variable a will not be available once the browser is redirected.

If I do:

--
request.session['a'] = 'aaaa'
render_to_response(...)
--

Then the session is available as expected.

I have tried to set:

request.session.modified = True

but that does not change the behavior.

Can session variables be set when doing a redirect?

mike


    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Rajesh Dhawan  
View profile  
 More options May 13 2008, 5:12 pm
From: Rajesh Dhawan <rajesh.dha...@gmail.com>
Date: Tue, 13 May 2008 14:12:32 -0700 (PDT)
Local: Tues, May 13 2008 5:12 pm
Subject: Re: do sessions work when redirecting?

On May 13, 3:23 pm, Mike Chambers <mikechamb...@gmail.com> wrote:

Absolutely.

You should ensure that request.META['HTTP_REFERER'] doesn't redirect
to a different domain name that happens to map to the same
application. For example, if you set the session in a view at
http://127.0.0.1/myview/ and that view redirects to http://localhost/myview2/,
you will not be able to access the previous session.


    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Mike Chambers  
View profile  
 More options May 13 2008, 5:50 pm
From: Mike Chambers <mikechamb...@gmail.com>
Date: Tue, 13 May 2008 14:50:19 -0700
Local: Tues, May 13 2008 5:50 pm
Subject: Re: do sessions work when redirecting?
Thanks for the input.

I am narrowing down the issue. Basically, If i try to place a copy of
the request.POST data into the session, nothing will get stored:

i.e.

--
post_copy = request.POST.copy()
request.session['form_post_data'] = post_copy
return HttpResponseRedirect(request.META['HTTP_REFERER'])
--

After this

request.session.keys() returns [] (an empty list)

if I do:

post_copy = request.POST.copy()
request.session['form_post_data'] = post_copy
print request.session.get('form_post_data')
return HttpResponseRedirect(request.META['HTTP_REFERER'])

this outputs:
--
<QueryDict: {u'comment': [u''], u'user_name': [u''], u'user_email':
[u''], u'user_url': [u'']}>
--

However, it it still not actually saved and available during a seperate
request.

mike


    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Mike Chambers  
View profile  
 More options May 13 2008, 6:04 pm
From: Mike Chambers <mikechamb...@gmail.com>
Date: Tue, 13 May 2008 15:04:09 -0700
Local: Tues, May 13 2008 6:04 pm
Subject: Re: do sessions work when redirecting?
I ended up getting this to work with (what feels like) a hack:

To save the session:

--
request.session['form_post_query_string'] = request.POST.urlencode()
return HttpResponseRedirect(request.META['HTTP_REFERER'])
--

then to later access it and use it:

--
from django.http import QueryDict

q = QueryDict(request.session['form_post_query_string'])
comment_form = CommentForm(q)
--

Anyone know why I cant store request.POST.copy() in the session?

Is that a bug?

mike


    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Mike Chambers  
View profile  
 More options May 13 2008, 7:50 pm
From: Mike Chambers <mikechamb...@gmail.com>
Date: Tue, 13 May 2008 16:50:42 -0700
Local: Tues, May 13 2008 7:50 pm
Subject: Re: do sessions work when redirecting?
ok. more info on this. (Sorry about all of the emails, but I am really
trying to track this down, and see if it is a bug).

If I try to include the request.POST data QueryDict in the session, then
no session data is saved between requests (i.e. it wipes other session
data):

request.session['form_post_data'] = request.POST.copy()
request.session['foo'] = "bar"

Then, in another request:

print request.session.keys()

prints []

But:

request.session['foo'] = "bar"

then in another request:

print request.session.keys()

prints ['foo']

So, at this point, Im thinking it is a bug.

mike


    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Juanjo Conti  
View profile  
 More options May 13 2008, 8:20 pm
From: "Juanjo Conti" <jjco...@gmail.com>
Date: Tue, 13 May 2008 21:20:24 -0300
Local: Tues, May 13 2008 8:20 pm
Subject: Re: do sessions work when redirecting?

On Tue, May 13, 2008 at 7:04 PM, Mike Chambers <mikechamb...@gmail.com> wrote:

>  Anyone know why I cant store request.POST.copy() in the session?

Not sure way, but I save it as a regular dict like this:

request.session['POST'] = dict(request.POST.items())

Greets!
--
Juanjo Conti


    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Mike Chambers  
View profile  
 More options May 14 2008, 1:21 am
From: Mike Chambers <mikechamb...@gmail.com>
Date: Tue, 13 May 2008 22:21:02 -0700
Local: Wed, May 14 2008 1:21 am
Subject: Re: do sessions work when redirecting?
fyi, bug logged here with test case:

http://code.djangoproject.com/ticket/7233

mike


    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Rajesh Dhawan  
View profile  
 More options May 14 2008, 2:55 pm
From: Rajesh Dhawan <rajesh.dha...@gmail.com>
Date: Wed, 14 May 2008 11:55:01 -0700 (PDT)
Local: Wed, May 14 2008 2:55 pm
Subject: Re: do sessions work when redirecting?
Hi Mike,

On May 14, 1:21 am, Mike Chambers <mikechamb...@gmail.com> wrote:

> fyi, bug logged here with test case:

> http://code.djangoproject.com/ticket/7233

I've just uploaded a patch to that ticket with an explanation.

Hopefully, you can test that.

-Rajesh


    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
End of messages
« Back to Discussions « Newer topic     Older topic »

Create a group - Google Groups - Google Home - Terms of Service - Privacy Policy
©2009 Google