fyi, bug logged here with test case:

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

mike


Mike Chambers wrote:
> 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
> 
> 
> Mike Chambers wrote:
>> 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
>>
>> Mike Chambers wrote:
>>> 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
>>>
>>>
>>> Rajesh Dhawan wrote:
>>>>
>>>>
>>>> On May 13, 3:23 pm, Mike Chambers <[EMAIL PROTECTED]> wrote:
>>>>> 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?
>>>>
>>>> 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.
>>>
>>>>

--~--~---------~--~----~------------~-------~--~----~
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 [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to