无法在django中上传少量带有表单的图片

时间:2017-06-28 13:26:36

标签: python django forms formset

我有django应用程序(django 1.6),我有问题发送少量图像,上传少量图像。在前端这是可以的,我可以拖放图像并在那里看到它们。

按下保存按钮时问题开始了。从前端上传的少量图片,现在我只能看到一个。因此,例如,从前端的2个上传图像,现在我只能看到一个。

以下是我上传图片的HTML:

For ready batches within then only after that promise resolves, but for other batches there is no promise. So they can get executed quickly.

这是我的<ul class="uploads"> {% for formset in forms%} {{ formset.management_form }} {% for a in formset %} {% if 'can_edit_posts' in perm_list or a.attachment.value %} <li class="{% if not a.attachment.value %}empty{% endif %}" data-form-name="{{ a.attachment.html_name }}"> {{ a.id }}{{ a.post_locale }} {{ a.attachment.value.url }} {{ a.attachment.html_name }} <div class="preview"> <div class="action"> <span class="icon-hospital">Add Image</span> </div> <img src="{% thumbnail a.attachment.value 400x400 autocrop=False %}" alt=""> <input class="upload-media" name="{{ a.attachment.html_name }}" type="file" value="{{ a.attachment.name }}" multiple> <input type="hidden" class="files-to-exclude"> </div> <div class="description"> <div class="filename">{{ a.attachment.value.name }}</div> <div class="filesize">{{ a.attachment.value.size }}</div> <ul class="btn-group"> <li class="download"> <a class="button icon-download-alt" href="{{ a.attachment.value.url }}" target="_blank"></a> </li> {% if formset.can_delete and 'can_edit_posts' in perm_list %} <li class="delete"> {{ a.DELETE }} <label for="{{a.DELETE.auto_id}}" class="button icon-trash"></label> </li> {% endif %} </ul> </div> <div class="previews"></div> </li> {% endif %} {% endfor %} {% endfor %} </ul>

self.request.POST

这是我的:self.request.FILES

<QueryDict: {u'FILES_4958-1-post_locale': [u'4958'], u'version': [u'1498653534877609:i1YC3hX-ReN2ZbdsDx4r8-eKGkQ', u'1498653534877609:i1YC3hX-ReN2ZbdsDx4r8-eKGkQ'], u'FILES_4959-TOTAL_FORMS': [u'1'], u'FILES_4958-4-post_locale': [u'4958'], u'FILES_4958-3-post_locale': [u'4958'], u'locales-0-id': [u'4958'], u'pub_date_1': [u'00:00'], u'pub_date_0': [u'29/06/2017'], u'FILES_4958-0-attachment': [u''], u'calendar': [u'33'], u'FILES_4958-3-attachment': [u''], u'FILES_4958-INITIAL_FORMS': [u'4'], u'promoted_to_0': [u'29/06/2017'], u'promoted_to_1': [u'00:00'], u'FILES_4959-0-post_locale': [u'4959'], u'FILES_4958-TOTAL_FORMS': [u'5'], u'FILES_4958-2-id': [u'4506'], u'promoted_from_1': [u'00:00'], u'theme': [u''], u'locales-TOTAL_FORMS': [u'2'], u'promoted_from_0': [u'29/06/2017'], u'FILES_4959-0-attachment': [u''], u'csrfmiddlewaretoken': [u'4pbI4tpoAiX5Fvms4kt424OZjFg1VNpH'], u'FILES_4958-3-id': [u'4507'], u'status': [u'0'], u'locales-0-locale': [u'60'], u'FILES_4958-1-attachment': [u''], u'locales-INITIAL_FORMS': [u'2'], u'FILES_4958-2-attachment': [u''], u'FILES_4959-MAX_NUM_FORMS': [u'1000'], u'locales-0-description': [u''], u'locales-1-description': [u''], u'FILES_4959-0-id': [u''], u'FILES_4958-1-id': [u'4505'], u'promoted_budget': [u''], u'locales-MAX_NUM_FORMS': [u'1000'], u'locales-1-id': [u'4959'], u'FILES_4959-INITIAL_FORMS': [u'0'], u'FILES_4958-4-id': [u''], u'FILES_4958-2-post_locale': [u'4958'], u'FILES_4958-0-id': [u'4504'], u'locales-1-locale': [u'59'], u'FILES_4958-MAX_NUM_FORMS': [u'1000'], u'FILES_4958-0-post_locale': [u'4958'], u'delete': [u'', u'']}>

我认为以下是<MultiValueDict: {u'FILES_4958-4-attachment': [<InMemoryUploadedFile: 14997117_765697240238061_1697922175_n.png (image/png)>, <InMemoryUploadedFile: 16010645_1347977721942284_325286987_o.jpg (image/jpeg)>]}> 方法:

form_valid

0 个答案:

没有答案