简体   繁体   中英

issue designing a template handling inlineformset_factory manually in django

My inlineformset_factory was working dandily until I decided to mess with the layout.

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. it somehow broke as a result of tampering with the 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; 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. I even tried wrapping it all in two divs out of sheer desperation and I did different permutations of the theme, alas no dice.

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:

{{ formset.management_form }} where 'formset' is the name of your formset.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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