[Answered ]-Formset is valid but returns empty cleaned_data field

1πŸ‘

βœ…

ok,
i just wanna complete the topic
so if anyone has the same problem, he/she can use this page to solve it
main keys to this solution are:
1- never forget the encryption type
2- use separate forms for different functionality

so in the template i should use:

<form method="POST" action="." encrypt="multipart/form-data">

and use two separate forms for add and delete files
like this:
this one for adding files:

<form method="POST" action="." encrypt="multipart/form-data" id="add_file">

and this one for deleting files:

<form method="POST" action="." encrypt="multipart/form-data" id="delete_file">

1πŸ‘

I ran into the same error message when I forgot to append the parenthesis () after is_valid. Formset.is_valid returned True, but there was no cleaned data simply because the is_valid() function was not called to return the cleaned data.

πŸ‘€rob70

0πŸ‘

I think you need to change the following line;

... snip ... 

for form in formset.forms:
    form_data = form.cleaned_data

... snip ...

You appear to be missing the .forms part from the formset.

πŸ‘€Reinbach

0πŸ‘

ok
i found out after using some break points, that it’s actually request’s fault, request.FILES is empty

0πŸ‘

tnx for all of your answers, i’v solved the problem,
i had one form with two functionality: add_file and del_file
after i separated them, every thing was ok
but there is a problem in the looking of the page
after i add some files, like 3 file and then request.POST sent and i return to the page again
i actually see three row of file input, instead of one
it really reduce the beauty
any advice?

Leave a comment