request.FILES.getlist()

622 views
Skip to first unread message

luca72.b...@gmail.com

unread,
Oct 7, 2020, 11:04:28 AM10/7/20
to Django users
i have a form that is like:
class tesoffcliForm(forms.Form)
        image = forms.FileField(label='Image', required = False)
        art_gen = forms.CharField(label='test ', required = False ,widget = forms.Textarea())  

the view is:

def testrendering(request):
    form = tesoffcliForm()
    number = range(100)
    return render(request, 'polls/test.html', {'form':form, 
    'range':number,  })

the template is:

{% for a in range %} 
        {% for field in form %}
            {{ field.label }} {{ field }}
            
            {% if forloop.counter|divisibleby:"2" %}
                <br><br>
            {% endif %}
        {% endfor %}

the view for get the data is very easy:

def get_data(request):

    art = request.POST.getlist('art_gen')
    image = request.FILES.getlist('image')

the list generated are:
art = a list of 100 lines, where if i have no imput in the list i find  '  '
image = a list with only the file that i have decide to upload.

how can i have also an empty folder in the image list??? for example
image = [file obg, ' ' , file obj 2, etc....]
if i can't do this i have no corrispondance between art and image when i save in the database

Thanks for your help

Dvs Khamele

unread,
Oct 11, 2020, 1:05:58 PM10/11/20
to django...@googlegroups.com
Hi do you hire contract based python/django freelancer?
 We can help you in this and related tasks at fair prices. Reply or send email to div...@pythonmate.com
Best Regards, 
Divyesh Khamele,
Pythonmate

--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/1f83f275-ab62-4b94-b314-81eda7ac2580n%40googlegroups.com.
Reply all
Reply to author
Forward
0 new messages