I receive an exception when I add a form to the session:
PicklingError: Can't pickle <class 'django.utils.functional.__proxy__'>: attribute lookup django.utils.functional.__proxy__ failed
The form includes a few simple fields and has some javascript attached to a widget. It might be that Django forms cannot be pickled at all, but the exception seems to point to unicode lazy translation.
To test further, I have also tried to insert only the form errors (an errordict) to the session and received the same error.
I appreciate some help here, thanks in advance.
EDIT: Here's why I insert a form into the session:
I have an app that has a form. This form is rendered by a template tag in another app. When posted, if the form is valid, no problem, I do stuff and redirect to "next". However if it is not valid, I want to go back to the posting page to show errors. Recall that the comments app in this case redirects to an intermediate "hey, please fix the errors" page. I am trying to avoid this, and hence redirect back to the posting page with the form and its errors in the session开发者_运维知识库 that the template tag will render.
You don't need to pickle form. If you want to store form value in the session, store form.cleaned_data
Based on whatever you have said, you are doing, you may want to checkout django form wizard. It pickles the data and stores it in the next forms as hidden values, you get all forms fields after completion.
I don't know how helpful this will be, but there is explanation of this type of error in JSON serializer
if validation fails put the request.POST in your sessions and redirect the user back as usual. your other view simply has to collect this and initialize forms with invalid data and the errors you found on your POST view will re-appear in the redirected view.
精彩评论