In my django application I have a multi step registration, with few conditional parameters. Because of this I figured out to store data from forms in session. Unfortunatelly sessions serialize data using pickle, which doesn't support file serialization and causes
PicklingError: Can't pickle <type 'cStringIO.StringO'>: attribute lookup cStringIO.StringO failed
. How to get around this problem ? Should I send image as a variable to all following views, or send it as a GET parameter or do it in some other way ? I'm not sure if any sample code is needed since problems seems pretty clear.
Asked
Active
Viewed 2,492 times
3

tom_pl
- 425
- 2
- 9
- 16
1 Answers
1
If the files that are being uploaded are larger than a few KB in size, then you probably don't want to store them in the session (and you definitely don't want to send them back to the browser via a GET).
I can think of a few options:
- You could rewrite your registration form so that uploaded files come last.
- You can make your form a single step, and fake the multi-step with javascript (by hiding and showing DIV's, for example).
- You could keep the temporary files on disk, and store the file names in the session (remembering to clean up old files periodically)
- You could simplify your registration, and do the file upload on a "profile" page (perhaps enforcing a "you have to fill out the profile" requirement before allowing access to the rest of the site).

Seth
- 45,033
- 10
- 85
- 120
-
I'm most interested in third method I guess since from what I know, django by itself store all files in temp. But how can I store just the path to the file not the file itself ? My debug shows that ImageFileField sends file object, not just a string path. – tom_pl Sep 11 '10 at 02:26