Django: Save cleaned_data in a session effectively
Asked Answered
C

1

4

In one of my forms, I am processing the form data and save it in a session variable.

So when I run

if locationForm.is_valid():

I execute

request.session['streetNumber'] = locationForm.cleaned_data['streetNumber']
request.session['postalCode'] = locationForm.cleaned_data['postalCode']
request.session['state'] = locationForm.cleaned_data['state']
request.session['country'] = locationForm.cleaned_data['country']

But this seems very inefficient. I have tried

request.session = locationForm.cleaned_data

but it does not seem to work.

  • Is there any better way of storing all cleaned_data information in a session variable?
  • Are there security concerns I should be aware off?
Cynth answered 10/12, 2011 at 2:43 Comment(0)
P
3

what about

for k, v in locationform.cleaned_data.iteritems():
  session[ k ] = v
Prowess answered 10/12, 2011 at 4:53 Comment(1)
Note iteritems() is dead and you can use items() nowProa

© 2022 - 2024 — McMap. All rights reserved.