简体   繁体   English

在Django中手动设计处理inlineformset_factory的模板时出现问题

[英]issue designing a template handling inlineformset_factory manually in django

My inlineformset_factory was working dandily until I decided to mess with the layout. 我的inlineformset_factory一直花哨的工作,直到我决定弄乱布局。

I've created an image based form that works off the already uploaded images (and a default image in case the spaces are not occupied) instead of the somewhat boring, grey input="file" button, and I get the error: "['ManagementForm data is missing or has been tampered with']" whenever I try to either upload a new image or delete an old one, eg. 我创建了一个基于图像的表单,该表单可以处理已上传的图像(如果不占用空间,则为默认图像),而不是有些无聊的灰色inp​​ut =“ file”按钮,但出现错误:“ [每当我尝试上载新图像或删除旧图像时,“ ManagementForm数据丢失或已被篡改”]“。 it somehow broke as a result of tampering with the HTML..? 它因篡改HTML而以某种方式破裂了。

In my template I have: 在我的模板中,我有:

<form method="POST" enctype="multipart/form-data">
{% for item in formset %}
{% csrf_token %}½
<div class="media context">
  <input type="file" id="formolator" accept="image/*" style="visibility:hidden;" />
  <label for="formolator">
    {% if item.extra_img.value != 'media/default.jpg' %}
    <img src="/media/{{ item.extra_img.value }}" class="img-box" />
    delete: {{ item.DELETE }}
    {% else %}
    <img src="/media/default.jpg" class="img-box" />
    {% endif %}
  </label>
</div>
{% endfor %}

<div class="form-group">
  <button class="btn btn-secondary ml-2 mb-2" type="submit">update</button>
</div>
</form>

Bonus conundrum: Aside from that, I've been trying to make the forms which show up in the template (in views I've set a limit at max_num=9) do a float:left; 额外的难题:除此之外,我一直在尝试使显示在模板中的表单(在视图中我已将限制设置为max_num = 9)执行float:left;。 in a few different ways. 以几种不同的方式。 Wrapping another div around the whole shebang like I've done in the template in which the images wind up upon upload to DB does not work for some reason, and I'm thinking whether it has to do with the nature of the input type, but I couldn't say. 像我在模板中那样在整个shebang上包装另一个div,在该模板中,由于某些原因,图像在上传到DB时结束时不起作用,并且我在考虑是否与输入类型的性质有关,但我不能说。 I even tried wrapping it all in two divs out of sheer desperation and I did different permutations of the theme, alas no dice. 出于绝望,我什至尝试将所有内容包装在两个div中,并且我对该主题进行了不同的排列,可惜没有骰子。

I encountered a similar problem recently. 我最近遇到了类似的问题。 I was able to correct the error by adding the following tag after the closing tag of the for-loop: 我可以通过在for循环的结束标记后添加以下标记来纠正错误:

{{ formset.management_form }} where 'formset' is the name of your formset. {{formset.management_form}},其中“ formset”是表单集的名称。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM