Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
如何遍历表单集以获取该表单中的每个表单和 FileField?
for file in formset.files: .... for form in formset.forms: ....
我希望在同一个循环中使用上述内容,因为我同时需要它们!
您的问题有点令人困惑,但如果您在同一个循环中查找表单对象和上传的文件,它看起来像这样:
# code for form in formset.forms: form.is_valid() # objective #1 accomplished the_file = form.cleaned_data['my_file_field'] # objective #2 accomplished
如果不是,请澄清。