Django和多图像上传表单 [英] Django and multi-image upload form
问题描述
问题是我还需要用户上传多个图像。我正在考虑在下一个页面上这样做。
我有两个问题:
- 将此多个图像上传表单添加到当前表单的最佳方式是什么?与Django无关,更多与表单的结构相关。
- 添加多个图像/文件以使Django正常工作的最佳方式是什么?任何用于此类工作的图书馆或模块或任何手动方式。
formets 允许用户一次创建多个图像。要从ImageForm创建一个表单,您可以执行以下操作:
>>> from django.forms.formsets import formset_factory
>>>> ImageFormSet = formset_factory(ImageForm)
https://docs.djangoproject.com/en/1.5/topics/forms/formsets/
Django附带了一个可选的表单向导应用程序,可以跨多个网页分割表单。它在一个后端维护状态,以便完整的服务器端处理可以延迟,直到提交最终形式。
https://docs.djangoproject.com/en/1.5/ref/contrib/formtools/form-向导/
I have this form that includes around 25 inputs on the same. It includes a main image input and the rest are some text inputs or drop down menus.
The problem is that I also need the user to upload multiple images. I was thinking of doing it on the next page itself.
I have 2 questions:
- What is the best way for adding this multiple image upload form to the current form? Not related to Django, more related to the structure of the form.
- What is the best way of adding a multiple image/file to work correctly with Django? Any libraries or modules for such a job or any manual way to do it.
With formsets you allow the user to create several images at once. To create a formset out of an ImageForm you would do:
>>> from django.forms.formsets import formset_factory
>>> ImageFormSet = formset_factory(ImageForm)
https://docs.djangoproject.com/en/1.5/topics/forms/formsets/
And Django comes with an optional "form wizard" application that splits forms across multiple Web pages. It maintains state in one of the backends so that the full server-side processing can be delayed until the submission of the final form.
https://docs.djangoproject.com/en/1.5/ref/contrib/formtools/form-wizard/
这篇关于Django和多图像上传表单的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!