[Answer]-Loop over forms in formset and a list at same time + FileField required error :django

1👍

In Django Templates, if you are trying to render a form that has a FileField. You must pass replace

<form method="post" action="">

with

<form method="POST" enctype="multipart/form-data">

https://docs.djangoproject.com/en/dev/ref/forms/api/#binding-uploaded-files-to-a-form

0👍

I’m afraid I don’t really understand your question, so apologies if this doesn’t help..

If your list is arbitary (as it looks from your question), then you could use django’s built in forloop counter to construct your file names –

{% for form in formset %}
    {{ form }}
    <input type="text" name="file_name" value="{% forloop.counter %}.png">
{% endfor %}

Alternatively have a look at python’s zip function. You could use it to build an object that includes both the names and the forms and pass that to your template.

Leave a comment